diff --git a/GoogleSignIn/Sources/GIDSignInButton.m b/GoogleSignIn/Sources/GIDSignInButton.m index 2d78330b..47552418 100644 --- a/GoogleSignIn/Sources/GIDSignInButton.m +++ b/GoogleSignIn/Sources/GIDSignInButton.m @@ -230,12 +230,17 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { } - (void)encodeWithCoder:(NSCoder *)aCoder { - [super encodeWithCoder:aCoder]; [aCoder encodeInteger:_style forKey:kStyleKey]; [aCoder encodeInteger:_colorScheme forKey:kColorSchemeKey]; [aCoder encodeInteger:_buttonState forKey:kButtonState]; } +#pragma mark - NSSecureCoding + ++ (BOOL)supportsSecureCoding { + return YES; +} + #pragma mark - UI - (void)updateUI { diff --git a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInButton.h b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInButton.h index f27488fb..af7ec99a 100644 --- a/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInButton.h +++ b/GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInButton.h @@ -46,7 +46,7 @@ typedef NS_ENUM(NSInteger, GIDSignInButtonColorScheme) { /// control to an `IBAction`, or something similar, that calls /// signInWithPresentingViewController:completion: on `GIDSignIn` and add it to your view /// hierarchy. -@interface GIDSignInButton : UIControl +@interface GIDSignInButton : UIControl /// The layout style for the sign-in button. /// Possible values: diff --git a/GoogleSignIn/Tests/Unit/GIDConfigurationTest.m b/GoogleSignIn/Tests/Unit/GIDConfigurationTest.m index 3c24b5e4..06e17141 100644 --- a/GoogleSignIn/Tests/Unit/GIDConfigurationTest.m +++ b/GoogleSignIn/Tests/Unit/GIDConfigurationTest.m @@ -99,9 +99,17 @@ - (void)testCoding { // Deprecated in iOS 13 and macOS 10.14 - (void)testLegacyCoding { GIDConfiguration *configuration = [GIDConfiguration testInstance]; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration]; - GIDConfiguration *newConfiguration = [NSKeyedUnarchiver unarchiveObjectWithData:data]; - XCTAssertEqualObjects(configuration, newConfiguration); + NSError *archivedError; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration + requiringSecureCoding:NO + error:&archivedError]; + XCTAssertNil(archivedError); + NSError *unArchivedError; + GIDConfiguration *newConfig = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDConfiguration class] + fromData:data + error:&unArchivedError]; + XCTAssertNil(unArchivedError); + XCTAssertEqualObjects(configuration, newConfig); XCTAssertTrue(GIDConfiguration.supportsSecureCoding); } #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST diff --git a/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m b/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m index f987c7c1..3c99084e 100644 --- a/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m +++ b/GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m @@ -133,8 +133,17 @@ - (void)testCoding { - (void)testLegacyCoding { GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:[OIDAuthState testInstance] profileData:[GIDProfileData testInstance]]; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user]; - GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + + NSError *archiveError; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user + requiringSecureCoding:NO + error:&archiveError]; + XCTAssertNil(archiveError); + NSError *unarchiveError; + GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDGoogleUser class] + fromData:data + error:&unarchiveError]; + XCTAssertNil(unarchiveError); XCTAssertEqualObjects(user, newUser); XCTAssertTrue(GIDGoogleUser.supportsSecureCoding); } diff --git a/GoogleSignIn/Tests/Unit/GIDProfileDataTest.m b/GoogleSignIn/Tests/Unit/GIDProfileDataTest.m index 10486693..df148649 100644 --- a/GoogleSignIn/Tests/Unit/GIDProfileDataTest.m +++ b/GoogleSignIn/Tests/Unit/GIDProfileDataTest.m @@ -138,8 +138,16 @@ - (void)testOldArchiveFormat { // Deprecated in iOS 13 and macOS 10.14 - (void)testLegacyCoding { GIDProfileData *profileData = [self profileData]; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profileData]; - GIDProfileData *newProfileData = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + NSError *archiveError; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profileData + requiringSecureCoding:NO + error:&archiveError]; + XCTAssertNil(archiveError); + NSError *unarchiveError; + GIDProfileData *newProfileData = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDProfileData class] + fromData:data + error:&unarchiveError]; + XCTAssertNil(unarchiveError); XCTAssertEqualObjects(profileData, newProfileData); XCTAssertTrue(GIDProfileData.supportsSecureCoding); } @@ -149,8 +157,16 @@ - (void)testOldArchiveFormatLegacy { name:kName imageURL:kFIFEImageURL]; [NSKeyedArchiver setClassName:@"GIDProfileData" forClass:[GIDProfileDataOld class]]; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:oldProfile]; - GIDProfileData *profileData = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + NSError *archiveError; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:oldProfile + requiringSecureCoding:NO + error:&archiveError]; + XCTAssertNil(archiveError); + NSError *unarchiveError; + GIDProfileData *profileData = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDProfileData class] + fromData:data + error:&unarchiveError]; + XCTAssertNil(unarchiveError); XCTAssertEqualObjects(profileData.email, kEmail); XCTAssertEqualObjects(profileData.name, kName); XCTAssertNil(profileData.givenName); diff --git a/GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m b/GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m index 658356e3..672bb922 100644 --- a/GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m +++ b/GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m @@ -73,8 +73,16 @@ - (void)testNSCoding { GIDSignInButton *button = [[GIDSignInButton alloc] init]; button.style = kGIDSignInButtonStyleIconOnly; button.colorScheme = kGIDSignInButtonColorSchemeLight; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:button]; - GIDSignInButton *newButton = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + NSError *archiveError; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:button + requiringSecureCoding:NO + error:&archiveError]; + XCTAssertNil(archiveError); + NSError *unarchiveError; + GIDSignInButton *newButton = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDSignInButton class] + fromData:data + error:&unarchiveError]; + XCTAssertNil(unarchiveError); XCTAssertEqual(button.style, newButton.style); XCTAssertEqual(button.colorScheme, newButton.colorScheme); }