FIRSecureStorage.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #import <Foundation/Foundation.h>
  17. @class FBLPromise<ValueType>;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /// The class provides a convenient abstraction on top of the iOS Keychain API to save data.
  20. @interface FIRSecureStorage : NSObject
  21. /**
  22. * Get an object by key.
  23. * @param key The key.
  24. * @param objectClass The expected object class required by `NSSecureCoding`.
  25. * @param accessGroup The Keychain Access Group.
  26. *
  27. * @return Returns a promise. It is resolved with an object stored by key if exists. It is resolved
  28. * with `nil` when the object not found. It fails on a Keychain error.
  29. */
  30. - (FBLPromise<id<NSSecureCoding>> *)getObjectForKey:(NSString *)key
  31. objectClass:(Class)objectClass
  32. accessGroup:(nullable NSString *)accessGroup;
  33. /**
  34. * Saves the given object by the given key.
  35. * @param object The object to store.
  36. * @param key The key to store the object. If there is an existing object by the key, it will be
  37. * overridden.
  38. * @param accessGroup The Keychain Access Group.
  39. *
  40. * @return Returns which is resolved with `[NSNull null]` on success.
  41. */
  42. - (FBLPromise<NSNull *> *)setObject:(id<NSSecureCoding>)object
  43. forKey:(NSString *)key
  44. accessGroup:(nullable NSString *)accessGroup;
  45. /**
  46. * Removes the object by the given key.
  47. * @param key The key to store the object. If there is an existing object by the key, it will be
  48. * overridden.
  49. * @param accessGroup The Keychain Access Group.
  50. *
  51. * @return Returns which is resolved with `[NSNull null]` on success.
  52. */
  53. - (FBLPromise<NSNull *> *)removeObjectForKey:(NSString *)key
  54. accessGroup:(nullable NSString *)accessGroup;
  55. #if TARGET_OS_OSX
  56. /// If not `nil`, then only this keychain will be used to save and read data (see
  57. /// `kSecMatchSearchList` and `kSecUseKeychain`. It is mostly intended to be used by unit tests.
  58. @property(nonatomic, nullable) SecKeychainRef keychainRef;
  59. #endif // TARGET_OSX
  60. @end
  61. NS_ASSUME_NONNULL_END