GTMKeychain.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*! @file GTMKeychain.h
  2. @brief GTMAppAuth SDK
  3. @copyright
  4. Copyright 2016 Google Inc.
  5. @copydetails
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  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. /*! @brief Utility for saving and loading data to the keychain.
  19. */
  20. @interface GTMKeychain : NSObject
  21. /*! @brief Saves the password string to the keychain with the given identifier.
  22. @param keychainItemName Keychain name of the item.
  23. @param password Password string to save.
  24. @return YES when the password string was saved successfully.
  25. */
  26. + (BOOL)savePasswordToKeychainForName:(NSString *)keychainItemName password:(NSString *)password;
  27. /*! @brief Loads the password string from the keychain with the given identifier.
  28. @param keychainItemName Keychain name of the item.
  29. @return The password string at the given identifier, or nil.
  30. */
  31. + (nullable NSString *)passwordFromKeychainForName:(NSString *)keychainItemName;
  32. /*! @brief Saves the password data to the keychain with the given identifier.
  33. @param keychainItemName Keychain name of the item.
  34. @param passwordData Password data to save.
  35. @return YES when the password data was saved successfully.
  36. */
  37. + (BOOL)savePasswordDataToKeychainForName:(NSString *)keychainItemName
  38. passwordData:(NSData *)passwordData;
  39. /*! @brief Loads the password data from the keychain with the given identifier.
  40. @param keychainItemName Keychain name of the item.
  41. @return The password data at the given identifier, or nil.
  42. */
  43. + (nullable NSData *)passwordDataFromKeychainForName:(NSString *)keychainItemName;
  44. /*! @brief Removes stored password string, such as when the user signs out.
  45. @param keychainItemName Keychain name of the item.
  46. @return YES if the password string was removed successfully (or didn't exist).
  47. */
  48. + (BOOL)removePasswordFromKeychainForName:(NSString *)keychainItemName;
  49. @end
  50. NS_ASSUME_NONNULL_END