Skip to content

Commit

Permalink
Merge pull request #3 from square/federman/cocoa_standard_enum_values
Browse files Browse the repository at this point in the history
Make VAL enum values follow Cocoa conventions
  • Loading branch information
dfed committed Jun 4, 2015
2 parents 9e427a5 + 24e6cf3 commit 5c5f8d6
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 87 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Or manually checkout the submodule with `git submodule add [email protected]:Square
### Basic Initialization

```
VALValet *myValet = [[VALValet alloc] initWithIdentifier:@"Druidia" accessibility:VALAccessibleWhenUnlocked];
VALValet *myValet = [[VALValet alloc] initWithIdentifier:@"Druidia" accessibility:VALAccessibilityWhenUnlocked];
```

To begin storing data securely using Valet, you need to create a VALValet instance with:
Expand All @@ -40,7 +40,7 @@ This instance can be used to store and retrieve data securely, but only when the

#### Choosing the Best Accessibility Value

The VALAccessibility enum is used to determine when your secrets can be accessed. It’s a good idea to use the strictest accessibility possible that will allow your app to function. For example, if your app does not run in the background you will want to ensure the secrets can only be read when the phone is unlocked by using `VALAccessibleWhenUnlocked` or `VALAccessibleWhenUnlockedThisDeviceOnly`.
The VALAccessibility enum is used to determine when your secrets can be accessed. It’s a good idea to use the strictest accessibility possible that will allow your app to function. For example, if your app does not run in the background you will want to ensure the secrets can only be read when the phone is unlocked by using `VALAccessibilityWhenUnlocked` or `VALAccessibilityWhenUnlockedThisDeviceOnly`.

### Reading and Writing

Expand All @@ -55,15 +55,15 @@ Valet’s API for securely reading and writing data is similar to that of an NSM
### Sharing Secrets Among Multiple Applications

```
VALValet *mySharedValet = [[VALValet alloc] initWithSharedAccessGroupIdentifier:@"Druidia" accessibility:VALAccessibleWhenUnlocked];
VALValet *mySharedValet = [[VALValet alloc] initWithSharedAccessGroupIdentifier:@"Druidia" accessibility:VALAccessibilityWhenUnlocked];
```

This instance can be used to store and retrieve data securely across any app writen by the same developer with the value `Druidia` under the `keychain-access-groups` key in the app’s `Entitlements` file, when the device is unlocked. `myValet` and `mySharedValet` can not read or modify one another’s values because the two Valets were created with different initializers. You can use the `-initWithSharedAccessGroupIdentifier:accessibility:` initializer on any Valet class to allow for sharing secrets across applications written by the same developer.

### Sharing Secrets Across Devices with iCloud

```
VALSynchronizableValet *mySynchronizableValet = [[VALSynchronizableValet alloc] initWithIdentifier:@"Druidia" accessibility:VALAccessibleWhenUnlocked];
VALSynchronizableValet *mySynchronizableValet = [[VALSynchronizableValet alloc] initWithIdentifier:@"Druidia" accessibility:VALAccessibilityWhenUnlocked];
```

This instance can be used to store and retrieve data that can be retrieved by this app on other devices logged into the same iCloud account with iCloud Keychain enabled. `mySynchronizableValet` can not read or modify values in `myValet` or `mySharedValet` because `mySynchronizableValet` is of a different class type. If iCloud Keychain is not enabled on this device, secrets can still be read and written, but will not sync to other devices.
Expand Down
2 changes: 1 addition & 1 deletion Valet.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Valet'
s.version = '1.0.0'
s.version = '1.1.0'
s.license = 'Apache'
s.summary = 'Valet lets you securely store data in the iOS or OS X Keychain without knowing a thing about how the Keychain works. It\'s easy. We promise.'
s.homepage = 'https://github.com/square/Valet'
Expand Down
2 changes: 1 addition & 1 deletion Valet/VALSecureEnclaveValet.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#import "VALValet.h"


/// Reads and writes keychain elements that are stored on the Secure Enclave (supported on iOS 8.0 or later) using accessibility attribute VALAccessibleWhenPasscodeSetThisDeviceOnly. Accessing or modifying these items will require the user to confirm their presence via Touch ID or passcode entry. If no passcode is set on the device, the below methods will fail. Data is removed from the Secure Enclave when the user removes a passcode from the device. Use the userPrompt methods to display custom text to the user in Apple's Touch ID and passcode entry UI.
/// Reads and writes keychain elements that are stored on the Secure Enclave (supported on iOS 8.0 or later) using accessibility attribute VALAccessibilityWhenPasscodeSetThisDeviceOnly. Accessing or modifying these items will require the user to confirm their presence via Touch ID or passcode entry. If no passcode is set on the device, the below methods will fail. Data is removed from the Secure Enclave when the user removes a passcode from the device. Use the userPrompt methods to display custom text to the user in Apple's Touch ID and passcode entry UI.
@interface VALSecureEnclaveValet : VALValet

/// Retuns YES if Secure Enclave storage is supported on the current iOS version (8.0 and later).
Expand Down
10 changes: 5 additions & 5 deletions Valet/VALSecureEnclaveValet.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ + (BOOL)supportsSecureEnclaveKeychainItems;

- (instancetype)initWithIdentifier:(NSString *)identifier;
{
return [self initWithIdentifier:identifier accessibility:VALAccessibleWhenPasscodeSetThisDeviceOnly];
return [self initWithIdentifier:identifier accessibility:VALAccessibilityWhenPasscodeSetThisDeviceOnly];
}

- (instancetype)initWithIdentifier:(NSString *)identifier accessibility:(VALAccessibility)accessibility;
{
VALCheckCondition(accessibility == VALAccessibleWhenPasscodeSetThisDeviceOnly, nil, @"Accessibility on SecureEnclaveValet must be VALAccessibleWhenPasscodeSetThisDeviceOnly");
VALCheckCondition(accessibility == VALAccessibilityWhenPasscodeSetThisDeviceOnly, nil, @"Accessibility on SecureEnclaveValet must be VALAccessibilityWhenPasscodeSetThisDeviceOnly");
VALCheckCondition([[self class] supportsSecureEnclaveKeychainItems], nil, @"This device does not support storing data on the secure enclave.");

return [super initWithIdentifier:identifier accessibility:accessibility];
}

- (instancetype)initWithSharedAccessGroupIdentifier:(NSString *)sharedAccessGroupIdentifier;
{
return [self initWithSharedAccessGroupIdentifier:sharedAccessGroupIdentifier accessibility:VALAccessibleWhenPasscodeSetThisDeviceOnly];
return [self initWithSharedAccessGroupIdentifier:sharedAccessGroupIdentifier accessibility:VALAccessibilityWhenPasscodeSetThisDeviceOnly];
}

- (instancetype)initWithSharedAccessGroupIdentifier:(NSString *)sharedAccessGroupIdentifier accessibility:(VALAccessibility)accessibility;
{
VALCheckCondition(accessibility == VALAccessibleWhenPasscodeSetThisDeviceOnly, nil, @"Accessibility on SecureEnclaveValet must be VALAccessibleWhenPasscodeSetThisDeviceOnly");
VALCheckCondition(accessibility == VALAccessibilityWhenPasscodeSetThisDeviceOnly, nil, @"Accessibility on SecureEnclaveValet must be VALAccessibilityWhenPasscodeSetThisDeviceOnly");
VALCheckCondition([[self class] supportsSecureEnclaveKeychainItems], nil, @"This device does not support storing data on the secure enclave.");

return [super initWithSharedAccessGroupIdentifier:sharedAccessGroupIdentifier accessibility:accessibility];
Expand Down Expand Up @@ -90,7 +90,7 @@ - (NSError *)migrateObjectsMatchingQuery:(NSDictionary *)secItemQuery removeOnCo
{
#if TARGET_OS_IPHONE && __IPHONE_8_0
if ([[self class] supportsSecureEnclaveKeychainItems]) {
VALCheckCondition(secItemQuery[(__bridge id)kSecUseOperationPrompt] == nil, [NSError errorWithDomain:VALMigrationErrorDomain code:VALMigrationInvalidQueryError userInfo:nil], @"kSecUseOperationPrompt is not supported in a migration query. Keychain items can not be migrated en masse from the Secure Enclave.");
VALCheckCondition(secItemQuery[(__bridge id)kSecUseOperationPrompt] == nil, [NSError errorWithDomain:VALMigrationErrorDomain code:VALMigrationErrorInvalidQuery userInfo:nil], @"kSecUseOperationPrompt is not supported in a migration query. Keychain items can not be migrated en masse from the Secure Enclave.");
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions Valet/VALSynchronizableValet.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ + (BOOL)supportsSynchronizableKeychainItems;

- (instancetype)initWithIdentifier:(NSString *)identifier accessibility:(VALAccessibility)accessibility;
{
VALCheckCondition(accessibility == VALAccessibleWhenUnlocked || accessibility == VALAccessibleAfterFirstUnlock || accessibility == VALAccessibleAlways, nil, @"Accessibility must not be scoped to this device");
VALCheckCondition(accessibility == VALAccessibilityWhenUnlocked || accessibility == VALAccessibilityAfterFirstUnlock || accessibility == VALAccessibilityAlways, nil, @"Accessibility must not be scoped to this device");
VALCheckCondition([[self class] supportsSynchronizableKeychainItems], nil, @"This device does not support synchronizing data to iCloud.");

return [super initWithIdentifier:identifier accessibility:accessibility];
}

- (instancetype)initWithSharedAccessGroupIdentifier:(NSString *)sharedAccessGroupIdentifier accessibility:(VALAccessibility)accessibility;
{
VALCheckCondition(accessibility == VALAccessibleWhenUnlocked || accessibility == VALAccessibleAfterFirstUnlock || accessibility == VALAccessibleAlways, nil, @"Accessibility must not be scoped to this device");
VALCheckCondition(accessibility == VALAccessibilityWhenUnlocked || accessibility == VALAccessibilityAfterFirstUnlock || accessibility == VALAccessibilityAlways, nil, @"Accessibility must not be scoped to this device");
VALCheckCondition([[self class] supportsSynchronizableKeychainItems], nil, @"This device does not support synchronizing data to iCloud.");

return [super initWithSharedAccessGroupIdentifier:sharedAccessGroupIdentifier accessibility:accessibility];
Expand Down
32 changes: 16 additions & 16 deletions Valet/VALValet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@

typedef NS_ENUM(NSUInteger, VALAccessibility) {
/// Valet data can only be accessed while the device is unlocked. This attribute is recommended for data that only needs to be accesible while the application is in the foreground. Valet data with this accessibility will migrate to a new device when using encrypted backups.
VALAccessibleWhenUnlocked = 1,
VALAccessibilityWhenUnlocked = 1,
/// Valet data can only be accessed once the device has been unlocked after a restart. This attribute is recommended for data that needs to be accesible by background applications. Valet data with this attribute will migrate to a new device when using encrypted backups.
VALAccessibleAfterFirstUnlock,
VALAccessibilityAfterFirstUnlock,
/// Valet data can always be accessed regardless of the lock state of the device. This attribute is not recommended. Valet data with this attribute will migrate to a new device when using encrypted backups.
VALAccessibleAlways,
VALAccessibilityAlways,

/// Valet data can only be accessed while the device is unlocked. This class is only available if a passcode is set on the device. This is recommended for items that only need to be accessible while the application is in the foreground. Valet data with this attribute will never migrate to a new device, so these items will be missing after a backup is restored to a new device. No items can be stored in this class on devices without a passcode. Disabling the device passcode will cause all items in this class to be deleted.
VALAccessibleWhenPasscodeSetThisDeviceOnly __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0),
VALAccessibilityWhenPasscodeSetThisDeviceOnly __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0),
/// Valet data can only be accessed while the device is unlocked. This is recommended for data that only needs to be accesible while the application is in the foreground. Valet data with this attribute will never migrate to a new device, so these items will be missing after a backup is restored to a new device.
VALAccessibleWhenUnlockedThisDeviceOnly,
VALAccessibilityWhenUnlockedThisDeviceOnly,
/// Valet data can only be accessed once the device has been unlocked after a restart. This is recommended for items that need to be accessible by background applications. Valet data with this attribute will never migrate to a new device, so these items will be missing after a backup is restored to a new device.
VALAccessibleAfterFirstUnlockThisDeviceOnly,
VALAccessibilityAfterFirstUnlockThisDeviceOnly,
/// Valet data can always be accessed regardless of the lock state of the device. This option is not recommended. Valet data with this attribute will never migrate to a new device, so these items will be missing after a backup is restored to a new device.
VALAccessibleAlwaysThisDeviceOnly,
VALAccessibilityAlwaysThisDeviceOnly,
};

extern NSString *const VALMigrationErrorDomain;

typedef NS_ENUM(NSUInteger, VALMigrationError) {
/// Migration failed because the keychain query was not valid.
VALMigrationInvalidQueryError = 1,
VALMigrationErrorInvalidQuery = 1,
/// Migration failed because no items to migrate were found.
VALMigrationNoItemsToMigrateFoundError,
VALMigrationErrorNoItemsToMigrateFound,
/// Migration failed because the keychain could not be read.
VALMigrationCouldNotReadKeychainError,
VALMigrationErrorCouldNotReadKeychain,
/// Migraiton failed because a key in the query result could not be read.
VALMigrationKeyInQueryResultInvalidError,
VALMigrationErrorKeyInQueryResultInvalid,
/// Migraiton failed because some data in the query result could not be read.
VALMigrationDataInQueryResultInvalidError,
VALMigrationErrorDataInQueryResultInvalid,
/// Migraiton failed because two keys with the same value were found in the keychain.
VALMigrationDuplicateKeyInQueryResultError,
VALMigrationErrorDuplicateKeyInQueryResult,
/// Migraiton failed because a key in the keychain duplicates a key already managed by Valet.
VALMigrationKeyInQueryResultAlreadyExistsInValetError,
VALMigrationErrorKeyInQueryResultAlreadyExistsInValet,
/// Migraiton failed because writing to the keychain failed.
VALMigrationCouldNotWriteToKeychainError,
VALMigrationErrorCouldNotWriteToKeychain,
/// Migration failed because removing the migrated data from the keychain failed.
VALMigrationRemovalFailedError,
VALMigrationErrorRemovalFailed,
};


Expand Down
Loading

0 comments on commit 5c5f8d6

Please sign in to comment.