commit | author | age
|
aca600
|
1 |
/* |
L |
2 |
* Copyright 2019 Google |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
|
|
17 |
#import <Foundation/Foundation.h> |
|
18 |
|
|
19 |
@class FBLPromise<ValueType>; |
|
20 |
|
|
21 |
NS_ASSUME_NONNULL_BEGIN |
|
22 |
|
|
23 |
/// The class provides a convenient, multiplatform abstraction of the Keychain. |
|
24 |
/// |
|
25 |
/// When using this API on macOS, the corresponding target must be signed with a provisioning |
|
26 |
/// profile that has the Keychain Sharing capability enabled. |
|
27 |
@interface GULKeychainStorage : NSObject |
|
28 |
|
|
29 |
- (instancetype)init NS_UNAVAILABLE; |
|
30 |
|
|
31 |
/** Initializes the keychain storage with Keychain Service name. |
|
32 |
* @param service A Keychain Service name that will be used to store and retrieve objects. See also |
|
33 |
* `kSecAttrService`. |
|
34 |
*/ |
|
35 |
- (instancetype)initWithService:(NSString *)service; |
|
36 |
|
|
37 |
/** |
|
38 |
* Get an object by key. |
|
39 |
* @param key The key. |
|
40 |
* @param objectClass The expected object class required by `NSSecureCoding`. |
|
41 |
* @param accessGroup The Keychain Access Group. |
|
42 |
* |
|
43 |
* @return Returns a promise. It is resolved with an object stored by key if exists. It is resolved |
|
44 |
* with `nil` when the object not found. It fails on a Keychain error. |
|
45 |
*/ |
|
46 |
- (FBLPromise<id<NSSecureCoding>> *)getObjectForKey:(NSString *)key |
|
47 |
objectClass:(Class)objectClass |
|
48 |
accessGroup:(nullable NSString *)accessGroup; |
|
49 |
|
|
50 |
/** |
|
51 |
* Saves the given object by the given key. |
|
52 |
* @param object The object to store. |
|
53 |
* @param key The key to store the object. If there is an existing object by the key, it will be |
|
54 |
* overridden. |
|
55 |
* @param accessGroup The Keychain Access Group. |
|
56 |
* |
|
57 |
* @return Returns which is resolved with `[NSNull null]` on success. |
|
58 |
*/ |
|
59 |
- (FBLPromise<NSNull *> *)setObject:(id<NSSecureCoding>)object |
|
60 |
forKey:(NSString *)key |
|
61 |
accessGroup:(nullable NSString *)accessGroup; |
|
62 |
|
|
63 |
/** |
|
64 |
* Removes the object by the given key. |
|
65 |
* @param key The key to store the object. If there is an existing object by the key, it will be |
|
66 |
* overridden. |
|
67 |
* @param accessGroup The Keychain Access Group. |
|
68 |
* |
|
69 |
* @return Returns which is resolved with `[NSNull null]` on success. |
|
70 |
*/ |
|
71 |
- (FBLPromise<NSNull *> *)removeObjectForKey:(NSString *)key |
|
72 |
accessGroup:(nullable NSString *)accessGroup; |
|
73 |
|
|
74 |
#if TARGET_OS_OSX |
|
75 |
/// If not `nil`, then only this keychain will be used to save and read data (see |
|
76 |
/// `kSecMatchSearchList` and `kSecUseKeychain`. It is mostly intended to be used by unit tests. |
|
77 |
@property(nonatomic, nullable) SecKeychainRef keychainRef; |
|
78 |
#endif // TARGET_OS_OSX |
|
79 |
|
|
80 |
@end |
|
81 |
|
|
82 |
NS_ASSUME_NONNULL_END |