Skip to content

Commit

Permalink
Use secure coding methods when available. (#145)
Browse files Browse the repository at this point in the history
* Use secure coding methods when available.

* Have pod lib lint fail on warnings.

* Check availability for all platforms.

* Fix indentation.

* Ignore deprecation warnings for (un)achiver methods.
  • Loading branch information
petea authored Sep 12, 2022
1 parent f2de574 commit 9ec2a9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install Ruby gems with Bundler
run: bundle install
- name: Lint podspec using local source
run: pod lib lint --verbose --allow-warnings
run: pod lib lint --verbose

spm-build-test:
runs-on: macOS-latest
Expand Down
27 changes: 24 additions & 3 deletions GTMAppAuth/Sources/GTMAppAuthFetcherAuthorization+Keychain.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ + (GTMAppAuthFetcherAuthorization *)authorizationFromKeychainForName:(NSString *
if (!passwordData) {
return nil;
}
GTMAppAuthFetcherAuthorization *authorization = (GTMAppAuthFetcherAuthorization *)
[NSKeyedUnarchiver unarchiveObjectWithData:passwordData];
GTMAppAuthFetcherAuthorization *authorization;
if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) {
authorization = (GTMAppAuthFetcherAuthorization *)
[NSKeyedUnarchiver unarchivedObjectOfClass:[GTMAppAuthFetcherAuthorization class]
fromData:passwordData
error:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
authorization = (GTMAppAuthFetcherAuthorization *)
[NSKeyedUnarchiver unarchiveObjectWithData:passwordData];
#pragma clang diagnostic pop
}
return authorization;
}

Expand Down Expand Up @@ -69,7 +80,17 @@ + (BOOL)saveAuthorization:(GTMAppAuthFetcherAuthorization *)auth
+ (BOOL)saveAuthorization:(GTMAppAuthFetcherAuthorization *)auth
toKeychainForName:(NSString *)keychainItemName
useDataProtectionKeychain:(BOOL)useDataProtectionKeychain {
NSData *authorizationData = [NSKeyedArchiver archivedDataWithRootObject:auth];
NSData *authorizationData;
if (@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) {
authorizationData = [NSKeyedArchiver archivedDataWithRootObject:auth
requiringSecureCoding:YES
error:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
authorizationData = [NSKeyedArchiver archivedDataWithRootObject:auth];
#pragma clang diagnostic pop
}
return [GTMKeychain savePasswordDataToKeychainForName:keychainItemName
passwordData:authorizationData
useDataProtectionKeychain:useDataProtectionKeychain];
Expand Down

0 comments on commit 9ec2a9c

Please sign in to comment.