No Description

FIRAuthKeychainServices.h 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2017 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. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. @brief The protocol for permanant data storage.
  20. */
  21. @protocol FIRAuthStorage <NSObject>
  22. /** @fn initWithService:
  23. @brief Initialize a @c FIRAuthStorage instance.
  24. @param service The name of the storage service to use.
  25. @return An initialized @c FIRAuthStorage instance for the specified service.
  26. */
  27. - (id<FIRAuthStorage>)initWithService:(NSString *)service;
  28. /** @fn dataForKey:error:
  29. @brief Gets the data for @c key in the storage. The key is set for the attribute
  30. @c kSecAttrAccount of a generic password query.
  31. @param key The key to use.
  32. @param error The address to store any error that occurs during the process, if not NULL.
  33. If the operation was successful, its content is set to @c nil .
  34. @return The data stored in the storage for @c key, if any.
  35. */
  36. - (nullable NSData *)dataForKey:(NSString *)key error:(NSError **_Nullable)error;
  37. /** @fn setData:forKey:error:
  38. @brief Sets the data for @c key in the storage. The key is set for the attribute
  39. @c kSecAttrAccount of a generic password query.
  40. @param data The data to store.
  41. @param key The key to use.
  42. @param error The address to store any error that occurs during the process, if not NULL.
  43. @return Whether the operation succeeded or not.
  44. */
  45. - (BOOL)setData:(NSData *)data forKey:(NSString *)key error:(NSError **_Nullable)error;
  46. /** @fn removeDataForKey:error:
  47. @brief Removes the data for @c key in the storage. The key is set for the attribute
  48. @c kSecAttrAccount of a generic password query.
  49. @param key The key to use.
  50. @param error The address to store any error that occurs during the process, if not NULL.
  51. @return Whether the operation succeeded or not.
  52. */
  53. - (BOOL)removeDataForKey:(NSString *)key error:(NSError **_Nullable)error;
  54. @end
  55. /** @class FIRAuthKeychain
  56. @brief The utility class to manipulate data in iOS Keychain.
  57. */
  58. @interface FIRAuthKeychainServices : NSObject <FIRAuthStorage>
  59. /** @fn getItemWithQuery:error:
  60. @brief Get the item from keychain by given query.
  61. @param query The query to query the keychain.
  62. @param outError The address to store any error that occurs during the process, if not nil.
  63. @return The item of the given query. nil if not exsit.
  64. */
  65. - (nullable NSData *)getItemWithQuery:(NSDictionary *)query
  66. error:(NSError *_Nullable *_Nullable)outError;
  67. /** @fn setItem:withQuery:error:
  68. @brief Set the item into keychain with given query.
  69. @param item The item to be added into keychain.
  70. @param query The query to query the keychain.
  71. @param outError The address to store any error that occurs during the process, if not nil.
  72. @return Whether the operation succeed.
  73. */
  74. - (BOOL)setItem:(NSData *)item withQuery:(NSDictionary *)query
  75. error:(NSError *_Nullable *_Nullable)outError;
  76. /** @fn getItemWithQuery:error:
  77. @brief Remove the item with given queryfrom keychain.
  78. @param query The query to query the keychain.
  79. @param outError The address to store any error that occurs during the process, if not nil.
  80. @return Whether the operation succeed.
  81. */
  82. - (BOOL)removeItemWithQuery:(NSDictionary *)query error:(NSError *_Nullable *_Nullable)outError;
  83. @end
  84. NS_ASSUME_NONNULL_END