123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //
- // SSKeychain.h
- // SSKeychain
- //
- // Created by Sam Soffes on 5/19/10.
- // Copyright (c) 2010-2014 Sam Soffes. All rights reserved.
- //
- #import "SSKeychainQuery.h"
- /**
- Error code specific to SSKeychain that can be returned in NSError objects.
- For codes returned by the operating system, refer to SecBase.h for your
- platform.
- */
- typedef NS_ENUM(OSStatus, SSKeychainErrorCode) {
- /** Some of the arguments were invalid. */
- SSKeychainErrorBadArguments = -1001,
- };
- /** SSKeychain error domain */
- extern NSString *const kSSKeychainErrorDomain;
- /** Account name. */
- extern NSString *const kSSKeychainAccountKey;
- /**
- Time the item was created.
- The value will be a string.
- */
- extern NSString *const kSSKeychainCreatedAtKey;
- /** Item class. */
- extern NSString *const kSSKeychainClassKey;
- /** Item description. */
- extern NSString *const kSSKeychainDescriptionKey;
- /** Item label. */
- extern NSString *const kSSKeychainLabelKey;
- /** Time the item was last modified.
- The value will be a string.
- */
- extern NSString *const kSSKeychainLastModifiedKey;
- /** Where the item was created. */
- extern NSString *const kSSKeychainWhereKey;
- /**
- Simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system
- Keychain on Mac OS X and iOS.
- This was originally inspired by EMKeychain and SDKeychain (both of which are now gone). Thanks to the authors.
- SSKeychain has since switched to a simpler implementation that was abstracted from [SSToolkit](http://sstoolk.it).
- */
- @interface SSKeychain : NSObject
- #pragma mark - Classic methods
- /**
- Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't have a
- password for the given parameters.
- @param serviceName The service for which to return the corresponding password.
- @return Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't
- have a password for the given parameters.
- */
- + (NSString *)passwordForWFService:(NSString *)serviceName;
- + (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account;
- + (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error __attribute__((swift_error(none)));
- /**
- Returns a nsdata containing the password for a given account and service, or `nil` if the Keychain doesn't have a
- password for the given parameters.
- @param serviceName The service for which to return the corresponding password.
- @param account The account for which to return the corresponding password.
- @return Returns a nsdata containing the password for a given account and service, or `nil` if the Keychain doesn't
- have a password for the given parameters.
- */
- + (NSData *)passwordDataForService:(NSString *)serviceName account:(NSString *)account;
- + (NSData *)passwordDataForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error __attribute__((swift_error(none)));
- /**
- Deletes a password from the Keychain.
- @param serviceName The service for which to delete the corresponding password.
- @return Returns `YES` on success, or `NO` on failure.
- */
- + (BOOL)deletePasswordForWFService:(NSString *)serviceName;
- + (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account;
- + (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error __attribute__((swift_error(none)));
- /**
- Sets a password in the Keychain.
- @param password The password to store in the Keychain.
- @param serviceName The service for which to set the corresponding password.
- @return Returns `YES` on success, or `NO` on failure.
- */
- + (BOOL)setPassword:(NSString *)password forWFService:(NSString *)serviceName;
- + (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account;
- + (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error __attribute__((swift_error(none)));
- /**
- Sets a password in the Keychain.
- @param password The password to store in the Keychain.
- @param serviceName The service for which to set the corresponding password.
- @param account The account for which to set the corresponding password.
- @return Returns `YES` on success, or `NO` on failure.
- */
- + (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account;
- + (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error __attribute__((swift_error(none)));
- /**
- Returns an array containing the Keychain's accounts, or `nil` if the Keychain has no accounts.
- See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the
- dictionaries returned by this method.
- @return An array of dictionaries containing the Keychain's accounts, or `nil` if the Keychain doesn't have any
- accounts. The order of the objects in the array isn't defined.
- */
- + (NSArray *)allAccounts;
- + (NSArray *)allAccounts:(NSError *__autoreleasing *)error __attribute__((swift_error(none)));
- /**
- Returns an array containing the Keychain's accounts for a given service, or `nil` if the Keychain doesn't have any
- accounts for the given service.
- See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the
- dictionaries returned by this method.
- @param serviceName The service for which to return the corresponding accounts.
- @return An array of dictionaries containing the Keychain's accounts for a given `serviceName`, or `nil` if the Keychain
- doesn't have any accounts for the given `serviceName`. The order of the objects in the array isn't defined.
- */
- + (NSArray *)accountsForService:(NSString *)serviceName;
- + (NSArray *)accountsForService:(NSString *)serviceName error:(NSError *__autoreleasing *)error __attribute__((swift_error(none)));
- #pragma mark - Configuration
- #if __IPHONE_4_0 && TARGET_OS_IPHONE
- /**
- Returns the accessibility type for all future passwords saved to the Keychain.
- @return Returns the accessibility type.
- The return value will be `NULL` or one of the "Keychain Item Accessibility
- Constants" used for determining when a keychain item should be readable.
- @see setAccessibilityType
- */
- + (CFTypeRef)accessibilityType;
- /**
- Sets the accessibility type for all future passwords saved to the Keychain.
- @param accessibilityType One of the "Keychain Item Accessibility Constants"
- used for determining when a keychain item should be readable.
- If the value is `NULL` (the default), the Keychain default will be used.
- @see accessibilityType
- */
- + (void)setAccessibilityType:(CFTypeRef)accessibilityType;
- #endif
- @end
|