From a4b621911edde288c3d432f91804d94c0c93c580 Mon Sep 17 00:00:00 2001 From: Andrew Urban Date: Wed, 30 Oct 2019 17:51:10 +0200 Subject: [PATCH 1/4] Improved archiving of OIDServiceDiscovery. --- Source/OIDServiceDiscovery.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/OIDServiceDiscovery.m b/Source/OIDServiceDiscovery.m index ca81108a8..051bbfc88 100644 --- a/Source/OIDServiceDiscovery.m +++ b/Source/OIDServiceDiscovery.m @@ -23,6 +23,10 @@ NS_ASSUME_NONNULL_BEGIN +/*! @brief The key for the @c discoveryDictionary property. + */ +static NSString *const kDiscoveryDictionaryKey = @"discoveryDictionary"; + /*! Field keys associated with an OpenID Connect Discovery Document. */ static NSString *const kIssuerKey = @"issuer"; static NSString *const kAuthorizationEndpointKey = @"authorization_endpoint"; @@ -191,7 +195,7 @@ + (BOOL)supportsSecureCoding { - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { NSError *error; - NSDictionary *dictionary = [[NSDictionary alloc] initWithCoder:aDecoder]; + NSDictionary *dictionary = [aDecoder decodeObjectOfClasses:[NSSet setWithObjects:[NSDictionary class], [NSArray class], nil] forKey:kDiscoveryDictionaryKey]; self = [self initWithDictionary:dictionary error:&error]; if (error) { return nil; @@ -200,7 +204,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { } - (void)encodeWithCoder:(NSCoder *)aCoder { - [_discoveryDictionary encodeWithCoder:aCoder]; + [aCoder encodeObject:_discoveryDictionary forKey:kDiscoveryDictionaryKey]; } #pragma mark - Properties From cf920f18c9e438a936a9313f267d707ea4575991 Mon Sep 17 00:00:00 2001 From: Andrew Urban Date: Thu, 31 Oct 2019 11:25:18 +0200 Subject: [PATCH 2/4] Improved tests to detect absence of support for [NSKeyedUnarchiver unarchivedObjectOfClass:fromData:error:] in OIDServiceDiscovery. --- UnitTests/OIDServiceDiscoveryTests.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/UnitTests/OIDServiceDiscoveryTests.m b/UnitTests/OIDServiceDiscoveryTests.m index b9a13ce86..98d22ff77 100644 --- a/UnitTests/OIDServiceDiscoveryTests.m +++ b/UnitTests/OIDServiceDiscoveryTests.m @@ -128,7 +128,7 @@ + (NSDictionary *)completeServiceDiscoveryDictionary { kTokenEndpointAuthSigningAlgorithmValuesSupportedKey : @"Token Endpoint Auth Signing Algorithm Values Supported", kDisplayValuesSupportedKey : @"Display Values Supported", - kClaimTypesSupportedKey : @"Claim Types Supported", + kClaimTypesSupportedKey : @[@"normal"], kClaimsSupportedKey : @"Claims Supported", kServiceDocumentationKey : @"Service Documentation", kClaimsLocalesSupportedKey : @"Claims Locales Supported", @@ -398,6 +398,12 @@ - (void)testSecureCoding { OIDServiceDiscovery *unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data]; XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @""); + + if (@available(iOS 11.0, *)) { + data = [NSKeyedArchiver archivedDataWithRootObject:discovery requiringSecureCoding:YES error:&error]; + unarchived = [NSKeyedUnarchiver unarchivedObjectOfClass:[OIDServiceDiscovery class] fromData:data error:&error]; + XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @""); + } } /*! @brief Tests the NSCopying implementation by round-tripping an instance through the copying From b9bb6a6ec7e07f44193ac0d6a50a33975416da91 Mon Sep 17 00:00:00 2001 From: Andrew Urban Date: Thu, 31 Oct 2019 11:54:06 +0200 Subject: [PATCH 3/4] Returned support of the pre-iOS 11. --- Source/OIDServiceDiscovery.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/OIDServiceDiscovery.m b/Source/OIDServiceDiscovery.m index 051bbfc88..974e9e1e0 100644 --- a/Source/OIDServiceDiscovery.m +++ b/Source/OIDServiceDiscovery.m @@ -195,7 +195,12 @@ + (BOOL)supportsSecureCoding { - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { NSError *error; - NSDictionary *dictionary = [aDecoder decodeObjectOfClasses:[NSSet setWithObjects:[NSDictionary class], [NSArray class], nil] forKey:kDiscoveryDictionaryKey]; + NSDictionary *dictionary = nil; + if (@available(iOS 11.0, *)) { + dictionary = [aDecoder decodeObjectOfClasses:[NSSet setWithObjects:[NSDictionary class], [NSArray class], nil] forKey:kDiscoveryDictionaryKey]; + } else { + dictionary = [[NSDictionary alloc] initWithCoder:aDecoder]; + } self = [self initWithDictionary:dictionary error:&error]; if (error) { return nil; @@ -204,7 +209,11 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { } - (void)encodeWithCoder:(NSCoder *)aCoder { - [aCoder encodeObject:_discoveryDictionary forKey:kDiscoveryDictionaryKey]; + if (@available(iOS 11.0, *)) { + [aCoder encodeObject:_discoveryDictionary forKey:kDiscoveryDictionaryKey]; + } else { + [_discoveryDictionary encodeWithCoder:aCoder]; + } } #pragma mark - Properties From fd9035e89a14c2ee3d30971f519447345d4e2907 Mon Sep 17 00:00:00 2001 From: Andrew Urban Date: Mon, 25 Nov 2019 17:32:35 +0200 Subject: [PATCH 4/4] Improved availability conditions to include other platforms than iOS --- Source/OIDServiceDiscovery.m | 4 ++-- UnitTests/OIDServiceDiscoveryTests.m | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/OIDServiceDiscovery.m b/Source/OIDServiceDiscovery.m index 974e9e1e0..13565e35d 100644 --- a/Source/OIDServiceDiscovery.m +++ b/Source/OIDServiceDiscovery.m @@ -196,7 +196,7 @@ + (BOOL)supportsSecureCoding { - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { NSError *error; NSDictionary *dictionary = nil; - if (@available(iOS 11.0, *)) { + if (@available(iOS 11.0, macCatalyst 13, macOS 10.13, tvOS 11, watchOS 4, *)) { dictionary = [aDecoder decodeObjectOfClasses:[NSSet setWithObjects:[NSDictionary class], [NSArray class], nil] forKey:kDiscoveryDictionaryKey]; } else { dictionary = [[NSDictionary alloc] initWithCoder:aDecoder]; @@ -209,7 +209,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { } - (void)encodeWithCoder:(NSCoder *)aCoder { - if (@available(iOS 11.0, *)) { + if (@available(iOS 11.0, macCatalyst 13, macOS 10.13, tvOS 11, watchOS 4, *)) { [aCoder encodeObject:_discoveryDictionary forKey:kDiscoveryDictionaryKey]; } else { [_discoveryDictionary encodeWithCoder:aCoder]; diff --git a/UnitTests/OIDServiceDiscoveryTests.m b/UnitTests/OIDServiceDiscoveryTests.m index 98d22ff77..27f26aa8c 100644 --- a/UnitTests/OIDServiceDiscoveryTests.m +++ b/UnitTests/OIDServiceDiscoveryTests.m @@ -399,7 +399,7 @@ - (void)testSecureCoding { XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @""); - if (@available(iOS 11.0, *)) { + if (@available(iOS 11.0, macCatalyst 13, macOS 10.13, tvOS 11, watchOS 4, *)) { data = [NSKeyedArchiver archivedDataWithRootObject:discovery requiringSecureCoding:YES error:&error]; unarchived = [NSKeyedUnarchiver unarchivedObjectOfClass:[OIDServiceDiscovery class] fromData:data error:&error]; XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @"");