Nav apraksta

FIRInstanceIDAuthKeyChain.h 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. extern NSString *__nonnull const kFIRInstanceIDKeychainWildcardIdentifier;
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * Wrapper around storing FCM auth data in iOS keychain.
  21. */
  22. @interface FIRInstanceIDAuthKeychain : NSObject
  23. /**
  24. * Designated Initializer. Init a generic `SecClassGenericPassword` keychain with `identifier`
  25. * as the `kSecAttrGeneric`.
  26. *
  27. * @param identifier The generic attribute to be used by the keychain.
  28. *
  29. * @return A Keychain object with `kSecAttrGeneric` attribute set to identifier.
  30. */
  31. - (instancetype)initWithIdentifier:(NSString *)identifier;
  32. /**
  33. * Get keychain items matching the given service and account. The service and/or account
  34. * can be a wildcard (`kFIRInstanceIDKeychainWildcardIdentifier`), which case the query
  35. * will include all items matching any services and/or accounts.
  36. *
  37. * @param service The kSecAttrService used to save the password. Can be wildcard.
  38. * @param account The kSecAttrAccount used to save the password. Can be wildcard.
  39. *
  40. * @return An array of |NSData|s matching the provided inputs.
  41. */
  42. - (NSArray<NSData *> *)itemsMatchingService:(NSString *)service account:(NSString *)account;
  43. /**
  44. * Get keychain item for a given service and account.
  45. *
  46. * @param service The kSecAttrService used to save the password.
  47. * @param account The kSecAttrAccount used to save the password.
  48. *
  49. * @return A cached keychain item for a given account and service, or nil if it was not
  50. * found or could not be retrieved.
  51. */
  52. - (NSData *)dataForService:(NSString *)service account:(NSString *)account;
  53. /**
  54. * Remove the cached items from the keychain matching the service, account and access group.
  55. * In case the items do not exist, YES is returned but with a valid error object with code
  56. * `errSecItemNotFound`.
  57. *
  58. * @param service The kSecAttrService used to save the password.
  59. * @param account The kSecAttrAccount used to save the password.
  60. * @param handler The callback handler which is invoked when the remove operation is complete, with
  61. * an error if there is any.
  62. */
  63. - (void)removeItemsMatchingService:(NSString *)service
  64. account:(NSString *)account
  65. handler:(nullable void (^)(NSError *error))handler;
  66. /**
  67. * Set the data for a given service and account with a specific accessibility. If
  68. * accessibility is NULL we use `kSecAttrAccessibleAlwaysThisDeviceOnly` which
  69. * prevents backup and restore to iCloud, and works for app extension that can
  70. * execute right after a device is restarted (and not unlocked).
  71. *
  72. * @param data The data to save.
  73. * @param service The `kSecAttrService` used to save the password.
  74. * @param accessibility The `kSecAttrAccessibility` used to save the password. If NULL
  75. * set this to `kSecAttrAccessibleAlwaysThisDeviceOnly`.
  76. * @param account The `kSecAttrAccount` used to save the password.
  77. * @param handler The callback handler which is invoked when the add operation is complete,
  78. * with an error if there is any.
  79. *
  80. */
  81. - (void)setData:(NSData *)data
  82. forService:(NSString *)service
  83. accessibility:(nullable CFTypeRef)accessibility
  84. account:(NSString *)account
  85. handler:(nullable void (^)(NSError *))handler;
  86. @end
  87. NS_ASSUME_NONNULL_END