1.1 --- a/MYKeychain.m Wed Apr 08 16:30:52 2009 -0700
1.2 +++ b/MYKeychain.m Thu Apr 09 22:46:48 2009 -0700
1.3 @@ -9,12 +9,15 @@
1.4 #import "MYKeychain.h"
1.5 #import "MYCrypto_Private.h"
1.6 #import "MYDigest.h"
1.7 +#import "MYIdentity.h"
1.8 +
1.9
1.10 #if !MYCRYPTO_USE_IPHONE_API
1.11
1.12
1.13 @interface MYKeyEnumerator : NSEnumerator
1.14 {
1.15 + @private
1.16 MYKeychain *_keychain;
1.17 SecKeychainSearchRef _search;
1.18 SecItemClass _itemClass;
1.19 @@ -27,6 +30,17 @@
1.20 @end
1.21
1.22
1.23 +@interface MYIdentityEnumerator : NSEnumerator
1.24 +{
1.25 + @private
1.26 + SecIdentitySearchRef _searchRef;
1.27 +}
1.28 +
1.29 +- (id) initWithKeychain: (MYKeychain*)keychain;
1.30 +@end
1.31 +
1.32 +
1.33 +
1.34
1.35 @implementation MYKeychain
1.36
1.37 @@ -249,6 +263,10 @@
1.38 attributes: NULL count: 0] autorelease];
1.39 }
1.40
1.41 +- (NSEnumerator*) enumerateIdentities {
1.42 + return [[[MYIdentityEnumerator alloc] initWithKeychain: self] autorelease];
1.43 +}
1.44 +
1.45 - (NSEnumerator*) enumerateSymmetricKeys {
1.46 return [[[MYKeyEnumerator alloc] initWithKeychain: self
1.47 itemClass: kSecSymmetricKeyItemClass
1.48 @@ -318,6 +336,12 @@
1.49 encoding: CSSM_CERT_ENCODING_BER];
1.50 }
1.51
1.52 +- (BOOL) addCertificate: (MYCertificate*)certificate {
1.53 + Assert(certificate);
1.54 + return check(SecCertificateAddToKeychain(certificate.certificateRef, self.keychainRefOrDefault),
1.55 + @"SecCertificateAddToKeychain");
1.56 +}
1.57 +
1.58
1.59 - (MYSymmetricKey*) generateSymmetricKeyOfSize: (unsigned)keySizeInBits
1.60 algorithm: (CCAlgorithm)algorithm
1.61 @@ -413,6 +437,31 @@
1.62 return key;
1.63 }
1.64
1.65 +@end
1.66 +
1.67 +
1.68 +
1.69 +@implementation MYIdentityEnumerator
1.70 +
1.71 +- (id) initWithKeychain: (MYKeychain*)keychain {
1.72 + self = [super init];
1.73 + if (self) {
1.74 + if (!check(SecIdentitySearchCreate(keychain.keychainRef, 0, &_searchRef),
1.75 + @"SecIdentitySearchCreate")) {
1.76 + [self release];
1.77 + return nil;
1.78 + }
1.79 + }
1.80 + return self;
1.81 +}
1.82 +
1.83 +- (id) nextObject {
1.84 + SecIdentityRef identityRef = NULL;
1.85 + OSStatus err = SecIdentitySearchCopyNext(_searchRef, &identityRef);
1.86 + if (err==errKCItemNotFound || !check(err, @"SecIdentitySearchCopyNext"))
1.87 + return nil;
1.88 + return [[[MYIdentity alloc] initWithIdentityRef: identityRef] autorelease];
1.89 +}
1.90
1.91 @end
1.92