Skip to content

Commit

Permalink
Merge pull request #468 from Simperium/develop
Browse files Browse the repository at this point in the history
Simperium Mark 0.7.9
  • Loading branch information
jleandroperez committed Mar 20, 2015
2 parents 496368d + 2cd3037 commit 14003a9
Show file tree
Hide file tree
Showing 40 changed files with 914 additions and 739 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@
// Copyright (c) 2010-2014 Sam Soffes. All rights reserved.
//

#import "SSKeychainQuery.h"
#import "SPKeychainQuery.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) {
typedef NS_ENUM(OSStatus, SPKeychainErrorCode) {
/** Some of the arguments were invalid. */
SSKeychainErrorBadArguments = -1001,
SPKeychainErrorBadArguments = -1001,
};

/** SSKeychain error domain */
extern NSString *const kSSKeychainErrorDomain;
extern NSString *const kSPKeychainErrorDomain;

/** Account name. */
extern NSString *const kSSKeychainAccountKey;
extern NSString *const kSPKeychainAccountKey;

/**
Time the item was created.
The value will be a string.
*/
extern NSString *const kSSKeychainCreatedAtKey;
extern NSString *const kSPKeychainCreatedAtKey;

/** Item class. */
extern NSString *const kSSKeychainClassKey;
extern NSString *const kSPKeychainClassKey;

/** Item description. */
extern NSString *const kSSKeychainDescriptionKey;
extern NSString *const kSPKeychainDescriptionKey;

/** Item label. */
extern NSString *const kSSKeychainLabelKey;
extern NSString *const kSPKeychainLabelKey;

/** Time the item was last modified.
The value will be a string.
*/
extern NSString *const kSSKeychainLastModifiedKey;
extern NSString *const kSPKeychainLastModifiedKey;

/** Where the item was created. */
extern NSString *const kSSKeychainWhereKey;
extern NSString *const kSPKeychainWhereKey;

/**
Simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system
Expand All @@ -56,7 +56,7 @@ extern NSString *const kSSKeychainWhereKey;
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
@interface SPKeychain : NSObject

#pragma mark - Classic methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
// Copyright (c) 2010-2014 Sam Soffes. All rights reserved.
//

#import "SSKeychain.h"
#import "SPKeychain.h"

NSString *const kSSKeychainErrorDomain = @"com.samsoffes.sskeychain";
NSString *const kSSKeychainAccountKey = @"acct";
NSString *const kSSKeychainCreatedAtKey = @"cdat";
NSString *const kSSKeychainClassKey = @"labl";
NSString *const kSSKeychainDescriptionKey = @"desc";
NSString *const kSSKeychainLabelKey = @"labl";
NSString *const kSSKeychainLastModifiedKey = @"mdat";
NSString *const kSSKeychainWhereKey = @"svce";
NSString *const kSPKeychainErrorDomain = @"com.samsoffes.sskeychain";
NSString *const kSPKeychainAccountKey = @"acct";
NSString *const kSPKeychainCreatedAtKey = @"cdat";
NSString *const kSPKeychainClassKey = @"labl";
NSString *const kSPKeychainDescriptionKey = @"desc";
NSString *const kSPKeychainLabelKey = @"labl";
NSString *const kSPKeychainLastModifiedKey = @"mdat";
NSString *const kSPKeychainWhereKey = @"svce";

#if __IPHONE_4_0 && TARGET_OS_IPHONE
static CFTypeRef SSKeychainAccessibilityType = NULL;
#endif

@implementation SSKeychain
@implementation SPKeychain

+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account {
return [self passwordForService:serviceName account:account error:nil];
}


+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error {
SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
SPKeychainQuery *query = [[SPKeychainQuery alloc] init];
query.service = serviceName;
query.account = account;
[query fetch:error];
Expand All @@ -43,7 +43,7 @@ + (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)acc


+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error {
SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
SPKeychainQuery *query = [[SPKeychainQuery alloc] init];
query.service = serviceName;
query.account = account;
return [query deleteItem:error];
Expand All @@ -56,7 +56,7 @@ + (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName acco


+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error {
SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
SPKeychainQuery *query = [[SPKeychainQuery alloc] init];
query.service = serviceName;
query.account = account;
query.password = password;
Expand All @@ -70,7 +70,7 @@ + (NSArray *)allAccounts {


+ (NSArray *)accountsForService:(NSString *)serviceName {
SSKeychainQuery *query = [[SSKeychainQuery alloc] init];
SPKeychainQuery *query = [[SPKeychainQuery alloc] init];
query.service = serviceName;
return [query fetchAll:nil];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
#endif

#ifdef SSKEYCHAIN_SYNCHRONIZATION_AVAILABLE
typedef NS_ENUM(NSUInteger, SSKeychainQuerySynchronizationMode) {
SSKeychainQuerySynchronizationModeAny,
SSKeychainQuerySynchronizationModeNo,
SSKeychainQuerySynchronizationModeYes
typedef NS_ENUM(NSUInteger, SPKeychainQuerySynchronizationMode) {
SPKeychainQuerySynchronizationModeAny,
SPKeychainQuerySynchronizationModeNo,
SPKeychainQuerySynchronizationModeYes
};
#endif

/**
Simple interface for querying or modifying keychain items.
*/
@interface SSKeychainQuery : NSObject
@interface SPKeychainQuery : NSObject

/** kSecAttrAccount */
@property (nonatomic, copy) NSString *account;
Expand All @@ -43,7 +43,7 @@ typedef NS_ENUM(NSUInteger, SSKeychainQuerySynchronizationMode) {

#ifdef SSKEYCHAIN_SYNCHRONIZATION_AVAILABLE
/** kSecAttrSynchronizable */
@property (nonatomic) SSKeychainQuerySynchronizationMode synchronizationMode;
@property (nonatomic) SPKeychainQuerySynchronizationMode synchronizationMode;
#endif

/** Root storage for password information */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Copyright (c) 2013-2014 Sam Soffes. All rights reserved.
//

#import "SSKeychainQuery.h"
#import "SSKeychain.h"
#import "SPKeychainQuery.h"
#import "SPKeychain.h"

@implementation SSKeychainQuery
@implementation SPKeychainQuery

@synthesize account = _account;
@synthesize service = _service;
Expand All @@ -27,7 +27,7 @@ @implementation SSKeychainQuery
#pragma mark - Public

- (BOOL)save:(NSError *__autoreleasing *)error {
OSStatus status = SSKeychainErrorBadArguments;
OSStatus status = SPKeychainErrorBadArguments;
if (!self.service || !self.account || !self.passwordData) {
if (error) {
*error = [[self class] errorWithCode:status];
Expand All @@ -43,7 +43,7 @@ - (BOOL)save:(NSError *__autoreleasing *)error {
[query setObject:self.label forKey:(__bridge id)kSecAttrLabel];
}
#if __IPHONE_4_0 && TARGET_OS_IPHONE
CFTypeRef accessibilityType = [SSKeychain accessibilityType];
CFTypeRef accessibilityType = [SPKeychain accessibilityType];
if (accessibilityType) {
[query setObject:(__bridge id)accessibilityType forKey:(__bridge id)kSecAttrAccessible];
}
Expand All @@ -59,7 +59,7 @@ - (BOOL)save:(NSError *__autoreleasing *)error {


- (BOOL)deleteItem:(NSError *__autoreleasing *)error {
OSStatus status = SSKeychainErrorBadArguments;
OSStatus status = SPKeychainErrorBadArguments;
if (!self.service || !self.account) {
if (error) {
*error = [[self class] errorWithCode:status];
Expand Down Expand Up @@ -89,7 +89,7 @@ - (BOOL)deleteItem:(NSError *__autoreleasing *)error {


- (NSArray *)fetchAll:(NSError *__autoreleasing *)error {
OSStatus status = SSKeychainErrorBadArguments;
OSStatus status = SPKeychainErrorBadArguments;
NSMutableDictionary *query = [self query];
[query setObject:@YES forKey:(__bridge id)kSecReturnAttributes];
[query setObject:(__bridge id)kSecMatchLimitAll forKey:(__bridge id)kSecMatchLimit];
Expand All @@ -106,7 +106,7 @@ - (NSArray *)fetchAll:(NSError *__autoreleasing *)error {


- (BOOL)fetch:(NSError *__autoreleasing *)error {
OSStatus status = SSKeychainErrorBadArguments;
OSStatus status = SPKeychainErrorBadArguments;
if (!self.service || !self.account) {
if (error) {
*error = [[self class] errorWithCode:status];
Expand Down Expand Up @@ -198,15 +198,15 @@ - (NSMutableDictionary *)query {
id value;

switch (self.synchronizationMode) {
case SSKeychainQuerySynchronizationModeNo: {
case SPKeychainQuerySynchronizationModeNo: {
value = @NO;
break;
}
case SSKeychainQuerySynchronizationModeYes: {
case SPKeychainQuerySynchronizationModeYes: {
value = @YES;
break;
}
case SSKeychainQuerySynchronizationModeAny: {
case SPKeychainQuerySynchronizationModeAny: {
value = (__bridge id)(kSecAttrSynchronizableAny);
break;
}
Expand All @@ -224,7 +224,7 @@ + (NSError *)errorWithCode:(OSStatus) code {
NSString *message = nil;
switch (code) {
case errSecSuccess: return nil;
case SSKeychainErrorBadArguments: message = NSLocalizedStringFromTable(@"SSKeychainErrorBadArguments", @"SSKeychain", nil); break;
case SPKeychainErrorBadArguments: message = NSLocalizedStringFromTable(@"SPKeychainErrorBadArguments", @"SSKeychain", nil); break;

#if TARGET_OS_IPHONE
case errSecUnimplemented: {
Expand Down Expand Up @@ -276,7 +276,7 @@ + (NSError *)errorWithCode:(OSStatus) code {
if (message) {
userInfo = @{ NSLocalizedDescriptionKey : message };
}
return [NSError errorWithDomain:kSSKeychainErrorDomain code:code userInfo:userInfo];
return [NSError errorWithDomain:kSPKeychainErrorDomain code:code userInfo:userInfo];
}

@end
Loading

0 comments on commit 14003a9

Please sign in to comment.