MYCertificate.h
author snej@snej.local
Sun Apr 12 22:16:14 2009 -0700 (2009-04-12)
changeset 9 aa5eb3fd6ebf
parent 2 8982b8fada63
child 16 c409dbc4f068
permissions -rw-r--r--
Doc touch-up
     1 //
     2 //  MYCertificate.h
     3 //  MYCrypto
     4 //
     5 //  Created by Jens Alfke on 3/26/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "MYKeychainItem.h"
    10 
    11 #if !TARGET_OS_IPHONE
    12 #import <Security/cssmtype.h>
    13 #endif
    14 
    15 @class MYPublicKey;
    16 
    17 
    18 /** An X.509 certificate. */
    19 @interface MYCertificate : MYKeychainItem {
    20     @private
    21     SecCertificateRef _certificateRef;
    22 }
    23 
    24 /** Creates a MYCertificate object for an existing Keychain certificate reference. */
    25 + (MYCertificate*) certificateWithCertificateRef: (SecCertificateRef)certificateRef;
    26 
    27 /** Initializes a MYCertificate object for an existing Keychain certificate reference. */
    28 - (id) initWithCertificateRef: (SecCertificateRef)certificateRef;
    29 
    30 /** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */
    31 - (id) initWithCertificateData: (NSData*)data;
    32 
    33 /** Checks whether two MYCertificate objects have bit-for-bit identical certificate data. */
    34 - (BOOL)isEqualToCertificate:(MYCertificate*)cert;
    35 
    36 /** The Keychain object reference for this certificate. */
    37 @property (readonly) SecCertificateRef certificateRef;
    38 
    39 /** The certificate's data. */
    40 @property (readonly) NSData *certificateData;
    41 
    42 /** The certificate's public key. */
    43 @property (readonly) MYPublicKey *publicKey;
    44 
    45 /** The name of the subject (owner) of the certificate. */
    46 @property (readonly) NSString *commonName;
    47 
    48 
    49 /** @name Mac-Only
    50  *  Functionality not available on iPhone. 
    51  */
    52 //@{
    53 #if !TARGET_OS_IPHONE
    54 
    55 /** Creates a MYCertificate object from exported key data, but does not add it to any keychain. */
    56 - (id) initWithCertificateData: (NSData*)data
    57                           type: (CSSM_CERT_TYPE) type
    58                       encoding: (CSSM_CERT_ENCODING) encoding;
    59 
    60 /** The list (if any) of the subject's email addresses. */
    61 @property (readonly) NSArray *emailAddresses;
    62 
    63 /** Finds the current 'preferred' certificate for the given name string. */
    64 + (MYCertificate*) preferredCertificateForName: (NSString*)name;
    65 
    66 /** Associates the receiver as the preferred certificate for the given name string. */
    67 - (BOOL) setPreferredCertificateForName: (NSString*)name;
    68 
    69 #endif
    70 //@}
    71 
    72 
    73 /** @name Expert
    74  */
    75 //@{
    76 #if !TARGET_OS_IPHONE
    77 
    78 + (SecPolicyRef) X509Policy;
    79 + (SecPolicyRef) SSLPolicy;
    80 + (SecPolicyRef) SMIMEPolicy;
    81 - (CSSM_CERT_TYPE) certificateType;
    82 - (NSArray*) trustSettings;
    83 - (BOOL) setUserTrust: (SecTrustUserSetting)trustSetting;
    84     
    85 #endif
    86 //@}
    87     
    88 @end
    89 
    90 
    91 NSString* MYPolicyGetName( SecPolicyRef policy );
    92 NSString* MYTrustDescribe( SecTrustRef trust );
    93 NSString* MYTrustResultDescribe( SecTrustResultType result );