mirror of https://github.com/oxen-io/session-ios
Respond to CR.
parent
eb616a3411
commit
cfb511aa57
@ -1 +1 @@
|
|||||||
Subproject commit 380e292c6670b734bc143b594a0b1a1204d4ab26
|
Subproject commit 06156f274a0c4ce9b742953a7ad0c8a916ecaa48
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
Loading…
Reference in New Issue