]> git.saurik.com Git - apple/security.git/blob - libsecurity_cdsa_utilities/lib/cssmcert.h
Security-55179.11.tar.gz
[apple/security.git] / libsecurity_cdsa_utilities / lib / cssmcert.h
1 /*
2 * Copyright (c) 2000-2004,2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // cssmcert - CSSM layer certificate (CL) related objects.
27 //
28 #ifndef _H_CSSMCERT
29 #define _H_CSSMCERT
30
31 #include <security_cdsa_utilities/cssmalloc.h>
32 #include <security_cdsa_utilities/cssmdata.h>
33
34
35 namespace Security {
36
37
38 //
39 // A CSSM_FIELD, essentially an OID/Data pair.
40 //
41 class CssmField : public PodWrapper<CssmField, CSSM_FIELD> {
42 public:
43 CssmField() { }
44 CssmField(const CSSM_OID &oid, const CSSM_DATA &value)
45 { FieldOid = oid; FieldValue = value; }
46
47 CssmField(const CSSM_OID &oid)
48 { FieldOid = oid; FieldValue = CssmData(); }
49
50 public:
51 CssmOid &oid() { return CssmOid::overlay(FieldOid); }
52 CssmOid &value() { return CssmOid::overlay(FieldValue); }
53 const CssmOid &oid() const { return CssmOid::overlay(FieldOid); }
54 const CssmOid &value() const { return CssmOid::overlay(FieldValue); }
55
56 bool isComplex() const
57 { return value().length() == CSSM_FIELDVALUE_COMPLEX_DATA_TYPE; }
58 };
59
60
61 //
62 // An encoded certificate
63 //
64 class EncodedCertificate : public PodWrapper<EncodedCertificate, CSSM_ENCODED_CERT> {
65 public:
66 EncodedCertificate(CSSM_CERT_TYPE type = CSSM_CERT_UNKNOWN,
67 CSSM_CERT_ENCODING enc = CSSM_CERT_ENCODING_UNKNOWN,
68 const CSSM_DATA *data = NULL);
69
70 CSSM_CERT_TYPE type() const { return CertType; }
71 CSSM_CERT_ENCODING encoding() const { return CertEncoding; }
72 const CssmData &blob() const { return CssmData::overlay(CertBlob); }
73
74 // CssmDataoid features
75 void *data() const { return blob().data(); }
76 size_t length() const { return blob().length(); }
77 };
78
79
80 //
81 // CertGroups - groups of certificates in a bewildering variety of forms
82 //
83 class CertGroup : public PodWrapper<CertGroup, CSSM_CERTGROUP> {
84 public:
85 CertGroup() { }
86 CertGroup(CSSM_CERT_TYPE ctype, CSSM_CERT_ENCODING encoding, CSSM_CERTGROUP_TYPE type);
87
88 public:
89 CSSM_CERT_TYPE certType() const { return CertType; }
90 CSSM_CERT_ENCODING encoding() const { return CertEncoding; }
91 CSSM_CERTGROUP_TYPE type() const { return CertGroupType; }
92 uint32 count() const { return NumCerts; }
93 uint32 &count() { return NumCerts; }
94
95 public:
96 // CSSM_CERTGROUP_DATA version
97 CssmData * &blobCerts()
98 { assert(type() == CSSM_CERTGROUP_DATA); return CssmData::overlayVar(GroupList.CertList); }
99 CssmData *blobCerts() const
100 { assert(type() == CSSM_CERTGROUP_DATA); return CssmData::overlay(GroupList.CertList); }
101
102 // CSSM_CERTGROUP_ENCODED_CERT version
103 EncodedCertificate * &encodedCerts()
104 { return EncodedCertificate::overlayVar(GroupList.EncodedCertList); }
105 EncodedCertificate *encodedCerts() const
106 { return EncodedCertificate::overlay(GroupList.EncodedCertList); }
107
108 public:
109 // free all memory in this group with the given allocator
110 void destroy(Allocator &allocator);
111 };
112
113
114 //
115 // Walkers
116 //
117 namespace DataWalkers {
118
119
120
121
122 } // end namespace DataWalkers
123 } // end namespace Security
124
125 #endif //_H_CSSMCERT