From 2d23c3aeaa38e888d3f61c6444dcee744bac4cd3 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Wed, 12 Aug 2020 11:42:23 +0200 Subject: [PATCH] IOSAD-180 Rename passphrase cache accessor --- pEpObjCAdapter/PEPInternalSession.m | 2 +- pEpObjCAdapter/PEPObjCAdapter.m | 4 ++-- pEpObjCAdapter/PEPPassphraseCache.h | 4 ++-- pEpObjCAdapter/PEPPassphraseCache.m | 2 +- pEpObjCAdapter/PEPPassphraseUtil.m | 12 ++++++------ pEpObjCTests/PEPSessionTest.m | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pEpObjCAdapter/PEPInternalSession.m b/pEpObjCAdapter/PEPInternalSession.m index a74fa22..fd24b1f 100644 --- a/pEpObjCAdapter/PEPInternalSession.m +++ b/pEpObjCAdapter/PEPInternalSession.m @@ -1162,7 +1162,7 @@ static NSDictionary *stringToRating; - (PEPPassphraseCache * _Nonnull)passphraseCache { - return [PEPPassphraseCache passphraseCache]; + return [PEPPassphraseCache sharedInstance]; } @end diff --git a/pEpObjCAdapter/PEPObjCAdapter.m b/pEpObjCAdapter/PEPObjCAdapter.m index 0fefbc3..48c352a 100644 --- a/pEpObjCAdapter/PEPObjCAdapter.m +++ b/pEpObjCAdapter/PEPObjCAdapter.m @@ -72,7 +72,7 @@ static id s_passphraseProvider = nil; { if (passphrase == nil) { s_passphraseForNewKeys = nil; - [[PEPPassphraseCache passphraseCache] setStoredPassphrase:passphrase]; + [[PEPPassphraseCache sharedInstance] setStoredPassphrase:passphrase]; return YES; } else { @@ -83,7 +83,7 @@ static id s_passphraseProvider = nil; } s_passphraseForNewKeys = normalizedPassphrase; - [[PEPPassphraseCache passphraseCache] setStoredPassphrase:passphrase]; + [[PEPPassphraseCache sharedInstance] setStoredPassphrase:passphrase]; return YES; } diff --git a/pEpObjCAdapter/PEPPassphraseCache.h b/pEpObjCAdapter/PEPPassphraseCache.h index 737dd17..af75243 100644 --- a/pEpObjCAdapter/PEPPassphraseCache.h +++ b/pEpObjCAdapter/PEPPassphraseCache.h @@ -32,8 +32,8 @@ extern const NSUInteger PEPPassphraseCacheMaxNumberOfPassphrases; /// should be reset. - (void)resetTimeoutForPassphrase:(NSString *)passphrase; -/// Get the (global) passphrase cache -+ (PEPPassphraseCache * _Nonnull)passphraseCache; +/// Get the (singleton) passphrase cache ++ (PEPPassphraseCache * _Nonnull)sharedInstance; @end diff --git a/pEpObjCAdapter/PEPPassphraseCache.m b/pEpObjCAdapter/PEPPassphraseCache.m index 27db3dd..a187200 100644 --- a/pEpObjCAdapter/PEPPassphraseCache.m +++ b/pEpObjCAdapter/PEPPassphraseCache.m @@ -158,7 +158,7 @@ PEPPassphraseCache * _Nullable g_passphraseCache; [self.mutablePassphraseEntries addObjectsFromArray:resultingPassphrases]; } -+ (PEPPassphraseCache * _Nonnull)passphraseCache ++ (PEPPassphraseCache * _Nonnull)sharedInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ diff --git a/pEpObjCAdapter/PEPPassphraseUtil.m b/pEpObjCAdapter/PEPPassphraseUtil.m index f1c8ff6..0d6c4fe 100644 --- a/pEpObjCAdapter/PEPPassphraseUtil.m +++ b/pEpObjCAdapter/PEPPassphraseUtil.m @@ -22,11 +22,11 @@ PEP_STATUS lastStatus = PEP_UNKNOWN_ERROR; NSMutableArray *passphrases = [NSMutableArray - arrayWithArray:[[PEPPassphraseCache passphraseCache] passphrases]]; + arrayWithArray:[[PEPPassphraseCache sharedInstance] passphrases]]; [passphrases insertObject:@"" atIndex:0]; - if ([[PEPPassphraseCache passphraseCache] storedPassphrase]) { - [passphrases insertObject:[[PEPPassphraseCache passphraseCache] storedPassphrase] atIndex:1]; + if ([[PEPPassphraseCache sharedInstance] storedPassphrase]) { + [passphrases insertObject:[[PEPPassphraseCache sharedInstance] storedPassphrase] atIndex:1]; } for (NSString *passphrase in passphrases) { @@ -40,7 +40,7 @@ if (lastStatus != PEP_PASSPHRASE_REQUIRED && lastStatus != PEP_WRONG_PASSPHRASE) { // The passphrase worked, so reset its timeout - [[PEPPassphraseCache passphraseCache] resetTimeoutForPassphrase:passphrase]; + [[PEPPassphraseCache sharedInstance] resetTimeoutForPassphrase:passphrase]; return (PEPStatus) lastStatus; } @@ -90,7 +90,7 @@ NSString *normalizedPassphrase = [lastPassphrase normalizedPassphraseWithError:nil]; //Add the new passphrase to our cache to not having to bother the client again. - [[PEPPassphraseCache passphraseCache] addPassphrase:normalizedPassphrase]; + [[PEPPassphraseCache sharedInstance] addPassphrase:normalizedPassphrase]; if (normalizedPassphrase == nil) { // Assume excessively long passphrase means PEP_WRONG_PASSPHRASE @@ -113,7 +113,7 @@ if (lastPassphraseProviderStatus != PEP_PASSPHRASE_REQUIRED && lastPassphraseProviderStatus != PEP_WRONG_PASSPHRASE) { // The passphrase worked, so reset its timeout - [[PEPPassphraseCache passphraseCache] resetTimeoutForPassphrase:lastPassphrase]; + [[PEPPassphraseCache sharedInstance] resetTimeoutForPassphrase:lastPassphrase]; return (PEPStatus) lastPassphraseProviderStatus; } diff --git a/pEpObjCTests/PEPSessionTest.m b/pEpObjCTests/PEPSessionTest.m index 5b78d0e..0ceed16 100644 --- a/pEpObjCTests/PEPSessionTest.m +++ b/pEpObjCTests/PEPSessionTest.m @@ -1647,7 +1647,7 @@ XCTAssertTrue([session mySelf:identMe error:&error]); XCTAssertNil(error); - [[PEPPassphraseCache passphraseCache] setStoredPassphrase:nil]; + [[PEPPassphraseCache sharedInstance] setStoredPassphrase:nil]; PEPPassphraseProviderMock *mock = [[PEPPassphraseProviderMock alloc] initWithPassphrases:@[]]; [PEPObjCAdapter setPassphraseProvider:mock];