Updated the README for the 0.1 release.
2 // MYCertificate-iPhone.m
5 // Created by Jens Alfke on 3/30/09.
6 // Copyright 2009 Jens Alfke. All rights reserved.
9 #import "MYCertificate.h"
10 #import "MYCrypto_Private.h"
12 #if MYCRYPTO_USE_IPHONE_API
15 @implementation MYCertificate
18 /** Creates a MYCertificate object for an existing Keychain certificate reference. */
19 - (id) initWithCertificateRef: (SecCertificateRef)certificateRef {
20 self = [super initWithKeychainItemRef: (SecKeychainItemRef)certificateRef];
22 _certificateRef = certificateRef; // superclass has already CFRetained it
27 /** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */
28 - (id) initWithCertificateData: (NSData*)data
30 SecCertificateRef certificateRef = SecCertificateCreateWithData(NULL, (CFDataRef)data);
31 self = [self initWithCertificateRef: certificateRef];
32 CFRelease(certificateRef);
37 @synthesize certificateRef=_certificateRef;
39 - (NSData*) certificateData {
40 CFDataRef data = SecCertificateCopyData(_certificateRef);
41 return data ?[(id)CFMakeCollectable(data) autorelease] :nil;
44 - (MYPublicKey*) publicKey {
45 SecTrustRef trust = NULL;
46 SecPolicyRef policy = SecPolicyCreateBasicX509();
47 OSStatus err = SecTrustCreateWithCertificates((CFArrayRef)$array((id)_certificateRef),
51 if (!check(err,@"SecTrustCreateWithCertificates"))
54 MYPublicKey *key = nil;
55 SecKeyRef keyRef = SecTrustCopyPublicKey(trust);
57 key = [[[MYPublicKey alloc] initWithKeyRef: keyRef] autorelease];
65 - (NSString*) commonName {
66 CFStringRef name = SecCertificateCopySubjectSummary(_certificateRef);
67 return name ?[(id)CFMakeCollectable(name) autorelease] :nil;
73 #endif MYCRYPTO_USE_IPHONE_API