Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent eb616a3411
commit cfb511aa57

@ -1 +1 @@
Subproject commit 380e292c6670b734bc143b594a0b1a1204d4ab26
Subproject commit 06156f274a0c4ce9b742953a7ad0c8a916ecaa48

@ -582,10 +582,10 @@ NSString *const kKeychainKey_LastRegisteredPhoneNumber = @"kKeychainKey_LastRegi
OWSCAssertDebug(value.length > 0);
NSError *error;
BOOL success = [CurrentAppContext().keychainStorage setWithString:value
service:kKeychainService_LastRegistered
key:key
error:&error];
BOOL success = [CurrentAppContext().keychainStorage setString:value
service:kKeychainService_LastRegistered
key:key
error:&error];
if (!success || error) {
OWSLogError(@"Error persisting 'last registered' value in keychain: %@", error);
}

@ -285,7 +285,7 @@ NS_ASSUME_NONNULL_BEGIN
- (id<KeychainStorage>)keychainStorage
{
return [SSKKeychainStorage sharedInstance];
return [SSKKeychainStorage shared];
}
- (NSString *)appDocumentDirectoryPath

@ -15,7 +15,7 @@ public enum KeychainStorageError: Error {
@objc func string(forService service: String, key: String) throws -> String
@objc func set(string: String, service: String, key: String) throws
@objc(setString:service:key:error:) func set(string: String, service: String, key: String) throws
@objc func data(forService service: String, key: String) throws -> Data
@ -29,7 +29,7 @@ public enum KeychainStorageError: Error {
@objc
public class SSKKeychainStorage: NSObject, KeychainStorage {
@objc public static let sharedInstance = SSKKeychainStorage()
@objc public static let shared = SSKKeychainStorage()
// Force usage as a singleton
override private init() {

@ -0,0 +1,52 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@objc
public class TestKeychainStorage: NSObject, KeychainStorage {
private var dataMap = [String: Data]()
override init() {
super.init()
}
@objc public func string(forService service: String, key: String) throws -> String {
let data = try self.data(forService: service, key: key)
guard let string = String(bytes: data, encoding: String.Encoding.utf8) else {
throw KeychainStorageError.failure(description: "\(logTag) could not retrieve string")
}
return string
}
@objc public func set(string: String, service: String, key: String) throws {
guard let data = string.data(using: String.Encoding.utf8) else {
throw KeychainStorageError.failure(description: "\(logTag) could not store data")
}
try set(data: data, service: service, key: key)
}
private func key(forService service: String, key: String) -> String {
return "\(service) \(key)"
}
@objc public func data(forService service: String, key: String) throws -> Data {
let key = self.key(forService: service, key: key)
guard let data = dataMap[key] else {
throw KeychainStorageError.failure(description: "\(logTag) could not retrieve data")
}
return data
}
@objc public func set(data: Data, service: String, key: String) throws {
let key = self.key(forService: service, key: key)
dataMap[key] = data
}
@objc public func remove(service: String, key: String) throws {
let key = self.key(forService: service, key: key)
dataMap.removeValue(forKey: key)
}
}

@ -3,7 +3,7 @@
//
#import "TestAppContext.h"
#import "TestKeychainStorage.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
@ -140,7 +140,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)appDocumentDirectoryPath
{
return self.mockAppDocumentDirectoryPath
return self.mockAppDocumentDirectoryPath;
}
- (NSString *)appSharedDataDirectoryPath

@ -1,15 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@protocol KeychainStorage;
@interface TestKeychainStorage : NSObject <KeychainStorage>
@property (nonatomic) NSMutableDictionary<NSString *, NSData *> *dataMap;
@end
NS_ASSUME_NONNULL_END

@ -1,123 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TestKeychainStorage.h"
#import "NSData+OWS.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
@implementation TestKeychainStorage
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
self.dataMap = [NSMutableDictionary new];
return self;
}
- (NSString *_Nullable)stringForKey:(NSString *)key
service:(NSString *)service
error:(NSError *_Nullable *_Nullable)error
{
OWSAssert(error);
OWSAssert(key.length > 0);
OWSAssert(service.length > 0);
if (error) {
*error = nil;
}
NSString *mapKey = [NSString stringWithFormat:@"%@-%@", service, key];
NSData *_Nullable data = self.dataMap[mapKey];
if (!data) {
NSLog(@"stringForKey:%@ service:%@ -> nil", key, service);
return nil;
}
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"stringForKey:%@ service:%@ -> %@", key, service, string);
return string;
}
- (BOOL)setWithString:(NSString *)string
forKey:(NSString *)key
service:(NSString *)service
error:(NSError *_Nullable *_Nullable)error
{
OWSAssert(error);
OWSAssert(key.length > 0);
OWSAssert(service.length > 0);
if (error) {
*error = nil;
}
NSLog(@"setWithString:%@ service:%@ -> %@", key, service, string);
NSString *mapKey = [NSString stringWithFormat:@"%@-%@", service, key];
self.dataMap[mapKey] = [string dataUsingEncoding:NSUTF8StringEncoding];
return YES;
}
- (NSData *_Nullable)dataForKey:(NSString *)key service:(NSString *)service error:(NSError *_Nullable *_Nullable)error
{
OWSAssert(error);
OWSAssert(key.length > 0);
OWSAssert(service.length > 0);
if (error) {
*error = nil;
}
NSString *mapKey = [NSString stringWithFormat:@"%@-%@", service, key];
NSData *_Nullable data = self.dataMap[mapKey];
NSLog(@"dataForKey:%@ service:%@ -> %@", key, service, data.hexadecimalString);
return data;
}
- (BOOL)setWithData:(NSData *)data
forKey:(NSString *)key
service:(NSString *)service
error:(NSError *_Nullable *_Nullable)error
{
OWSAssert(error);
OWSAssert(key.length > 0);
OWSAssert(service.length > 0);
if (error) {
*error = nil;
}
NSLog(@"setWithData:%@ service:%@ -> %@", key, service, data.hexadecimalString);
NSString *mapKey = [NSString stringWithFormat:@"%@-%@", service, key];
self.dataMap[mapKey] = data;
return YES;
}
- (BOOL)removeWithKey:(NSString *)key service:(NSString *)service error:(NSError *_Nullable *_Nullable)error
{
OWSAssert(error);
OWSAssert(key.length > 0);
OWSAssert(service.length > 0);
if (error) {
*error = nil;
}
NSLog(@"removeWithKey:%@ service:%@", key, service);
NSString *mapKey = [NSString stringWithFormat:@"%@-%@", service, key];
[self.dataMap removeObjectForKey:mapKey];
return YES;
}
@end
NS_ASSUME_NONNULL_END

@ -216,7 +216,7 @@ NS_ASSUME_NONNULL_BEGIN
- (id<KeychainStorage>)keychainStorage
{
return [SSKKeychainStorage sharedInstance];
return [SSKKeychainStorage shared];
}
- (NSString *)appDocumentDirectoryPath

Loading…
Cancel
Save