Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/*
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 abstraction on top of the iOS Keychain API to save data.
24
@interface GULKeychainStorage : NSObject
25
 
26
- (instancetype)init NS_UNAVAILABLE;
27
 
28
/** Initializes the keychain storage with Keychain Service name.
29
 *  @param service A Keychain Service name that will be used to store and retrieve objects. See also
30
 * `kSecAttrService`.
31
 */
32
- (instancetype)initWithService:(NSString *)service;
33
 
34
/**
35
 * Get an object by key.
36
 * @param key The key.
37
 * @param objectClass The expected object class required by `NSSecureCoding`.
38
 * @param accessGroup The Keychain Access Group.
39
 *
40
 * @return Returns a promise. It is resolved with an object stored by key if exists. It is resolved
41
 * with `nil` when the object not found. It fails on a Keychain error.
42
 */
43
- (FBLPromise<id<NSSecureCoding>> *)getObjectForKey:(NSString *)key
44
                                        objectClass:(Class)objectClass
45
                                        accessGroup:(nullable NSString *)accessGroup;
46
 
47
/**
48
 * Saves the given object by the given key.
49
 * @param object The object to store.
50
 * @param key The key to store the object. If there is an existing object by the key, it will be
51
 * overridden.
52
 * @param accessGroup The Keychain Access Group.
53
 *
54
 * @return Returns which is resolved with `[NSNull null]` on success.
55
 */
56
- (FBLPromise<NSNull *> *)setObject:(id<NSSecureCoding>)object
57
                             forKey:(NSString *)key
58
                        accessGroup:(nullable NSString *)accessGroup;
59
 
60
/**
61
 * Removes the object by the given key.
62
 * @param key The key to store the object. If there is an existing object by the key, it will be
63
 * overridden.
64
 * @param accessGroup The Keychain Access Group.
65
 *
66
 * @return Returns which is resolved with `[NSNull null]` on success.
67
 */
68
- (FBLPromise<NSNull *> *)removeObjectForKey:(NSString *)key
69
                                 accessGroup:(nullable NSString *)accessGroup;
70
 
71
#if TARGET_OS_OSX
72
/// If not `nil`, then only this keychain will be used to save and read data (see
73
/// `kSecMatchSearchList` and `kSecUseKeychain`. It is mostly intended to be used by unit tests.
74
@property(nonatomic, nullable) SecKeychainRef keychainRef;
75
#endif  // TARGET_OSX
76
 
77
@end
78
 
79
NS_ASSUME_NONNULL_END