]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/clAppUtils/CertParser.h
Security-57031.10.10.tar.gz
[apple/security.git] / SecurityTests / clxutils / clAppUtils / CertParser.h
1 /*
2 * Copyright (c) 2003-2005 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please
7 * obtain a copy of the License at http://www.apple.com/publicsource and
8 * read it before using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
12 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
13 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
15 * Please see the License for the specific language governing rights and
16 * limitations under the License.
17 */
18
19 /*
20 * CertParser.h - cert parser with autorelease of fetched fields
21 *
22 * Created 24 October 2003 by Doug Mitchell
23 */
24
25 #ifndef _CERT_PARSER_H_
26 #define _CERT_PARSER_H_
27
28 #include <Security/Security.h>
29 #include <vector>
30
31 using std::vector;
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*
38 * We store an vector<> of these as an "autorelease" pool of fetched fields.
39 */
40 class CP_FetchedField;
41
42 class CertParser
43 {
44 public:
45 /*
46 * Construct with or without data - you can add the data later with
47 * initWithData() to parse without exceptions
48 */
49
50 CertParser(); // must be used with initWithSecCert to get clHand
51 CertParser( // use with initWithData
52 CSSM_CL_HANDLE clHand);
53 CertParser(
54 CSSM_CL_HANDLE clHand,
55 const CSSM_DATA &certData);
56 CertParser(
57 SecCertificateRef secCert);
58
59 /* frees all the fields we fetched */
60 ~CertParser();
61
62 /*
63 * No cert- or CDSA-related exceptions thrown by remainder
64 */
65 CSSM_RETURN initWithData(
66 const CSSM_DATA &certData);
67 OSStatus initWithSecCert(
68 SecCertificateRef secCert);
69 CSSM_RETURN initWithCFData(
70 CFDataRef cfData);
71
72 /*
73 * Obtain atrbitrary field from cached cert. This class takes care of freeing
74 * the field in its destructor.
75 *
76 * Returns NULL if field not found (not exception).
77 *
78 * Caller optionally specifies field length to check - specifying zero means
79 * "don't care, don't check". Actual field length always returned in fieldLength.
80 */
81 const void *fieldForOid(
82 const CSSM_OID &oid,
83 CSSM_SIZE &fieldLength); // IN/OUT
84
85 /*
86 * Conveneince routine to fetch an extension we "know" the CL can parse.
87 * The return value gets cast to one of the CE_Data types.
88 */
89 const void *extensionForOid(
90 const CSSM_OID &oid);
91
92 private:
93 void initFields();
94
95 CSSM_CL_HANDLE mClHand;
96 CSSM_HANDLE mCacheHand; // the parsed & cached cert
97 vector<CP_FetchedField *> mFetchedFields;
98 };
99
100 #ifdef __cplusplus
101 }
102 #endif
103
104 #endif /* _CERT_PARSER_H_ */
105