MYIdentity.m
changeset 12 e4c971be4079
parent 5 b2e360b78189
child 14 3af1d1c0ceb5
     1.1 --- a/MYIdentity.m	Thu Apr 09 22:27:51 2009 -0700
     1.2 +++ b/MYIdentity.m	Sat Apr 18 18:12:06 2009 -0700
     1.3 @@ -13,6 +13,11 @@
     1.4  @implementation MYIdentity
     1.5  
     1.6  
     1.7 +/** Creates a MYIdentity object for an existing Keychain identity reference. */
     1.8 ++ (MYIdentity*) identityWithIdentityRef: (SecIdentityRef)identityRef {
     1.9 +    return [[[self alloc] initWithIdentityRef: identityRef] autorelease];
    1.10 +}
    1.11 +
    1.12  - (id) initWithIdentityRef: (SecIdentityRef)identityRef {
    1.13      Assert(identityRef);
    1.14      SecCertificateRef certificateRef;
    1.15 @@ -57,6 +62,8 @@
    1.16  }
    1.17  
    1.18  
    1.19 +@synthesize identityRef=_identityRef;
    1.20 +
    1.21  - (MYPrivateKey*) privateKey {
    1.22      SecKeyRef keyRef = NULL;
    1.23      if (!check(SecIdentityCopyPrivateKey(_identityRef, &keyRef), @"SecIdentityCopyPrivateKey"))
    1.24 @@ -74,10 +81,10 @@
    1.25  {
    1.26      Assert(name);
    1.27      SecIdentityRef identityRef;
    1.28 -    if (!check(SecIdentityCopyPreference((CFStringRef)name, 0, NULL, &identityRef),
    1.29 -               @"SecIdentityCopyPreference"))
    1.30 +    OSStatus err = SecIdentityCopyPreference((CFStringRef)name, 0, NULL, &identityRef);
    1.31 +    if (err==errKCItemNotFound || !check(err,@"SecIdentityCopyPreference") || !identityRef)
    1.32          return nil;
    1.33 -    return identityRef ?[[[self alloc] initWithIdentityRef: identityRef] autorelease] :nil;
    1.34 +    return [self identityWithIdentityRef: identityRef];
    1.35  }
    1.36  
    1.37  - (BOOL) makePreferredIdentityForName: (NSString*)name {