]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/cssmcert.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / cssmcert.h
1 /*
2 * Copyright (c) 2000-2002 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 obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * 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 EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // cssmcert - CSSM layer certificate (CL) related objects.
21 //
22 #ifndef _H_CSSMCERT
23 #define _H_CSSMCERT
24
25 #include <Security/utilities.h>
26 #include <Security/cssmalloc.h>
27
28
29 namespace Security {
30
31
32 //
33 // A CSSM_FIELD, essentially an OID/Data pair.
34 //
35 class CssmField : public PodWrapper<CssmField, CSSM_FIELD> {
36 public:
37 CssmField() { }
38 CssmField(const CSSM_OID &oid, const CSSM_DATA &value)
39 { FieldOid = oid; FieldValue = value; }
40
41 CssmField(const CSSM_OID &oid)
42 { FieldOid = oid; FieldValue = CssmData(); }
43
44 public:
45 CssmOid &oid() { return CssmOid::overlay(FieldOid); }
46 CssmOid &value() { return CssmOid::overlay(FieldValue); }
47 const CssmOid &oid() const { return CssmOid::overlay(FieldOid); }
48 const CssmOid &value() const { return CssmOid::overlay(FieldValue); }
49
50 bool isComplex() const
51 { return value().length() == CSSM_FIELDVALUE_COMPLEX_DATA_TYPE; }
52 };
53
54
55 //
56 // An encoded certificate
57 //
58 class EncodedCertificate : public PodWrapper<EncodedCertificate, CSSM_ENCODED_CERT> {
59 public:
60 EncodedCertificate(CSSM_CERT_TYPE type = CSSM_CERT_UNKNOWN,
61 CSSM_CERT_ENCODING enc = CSSM_CERT_ENCODING_UNKNOWN,
62 const CSSM_DATA *data = NULL);
63
64 CSSM_CERT_TYPE type() const { return CertType; }
65 CSSM_CERT_ENCODING encoding() const { return CertEncoding; }
66 const CssmData &blob() const { return CssmData::overlay(CertBlob); }
67
68 // CssmDataoid features
69 void *data() const { return blob().data(); }
70 size_t length() const { return blob().length(); }
71 };
72
73
74 //
75 // CertGroups - groups of certificates in a bewildering variety of forms
76 //
77 class CertGroup : public PodWrapper<CertGroup, CSSM_CERTGROUP> {
78 public:
79 CertGroup() { }
80 CertGroup(CSSM_CERT_TYPE ctype, CSSM_CERT_ENCODING encoding, CSSM_CERTGROUP_TYPE type);
81
82 public:
83 CSSM_CERT_TYPE certType() const { return CertType; }
84 CSSM_CERT_ENCODING encoding() const { return CertEncoding; }
85 CSSM_CERTGROUP_TYPE type() const { return CertGroupType; }
86 uint32 count() const { return NumCerts; }
87 uint32 &count() { return NumCerts; }
88
89 public:
90 // CSSM_CERTGROUP_DATA version
91 CssmData * &blobCerts()
92 { assert(type() == CSSM_CERTGROUP_DATA); return CssmData::overlayVar(GroupList.CertList); }
93 CssmData *blobCerts() const
94 { assert(type() == CSSM_CERTGROUP_DATA); return CssmData::overlay(GroupList.CertList); }
95
96 // CSSM_CERTGROUP_ENCODED_CERT version
97 EncodedCertificate * &encodedCerts()
98 { return EncodedCertificate::overlayVar(GroupList.EncodedCertList); }
99 EncodedCertificate *encodedCerts() const
100 { return EncodedCertificate::overlay(GroupList.EncodedCertList); }
101
102 public:
103 // free all memory in this group with the given allocator
104 void destroy(CssmAllocator &allocator);
105 };
106
107
108 //
109 // Walkers
110 //
111 namespace DataWalkers {
112
113
114
115
116 } // end namespace DataWalkers
117 } // end namespace Security
118
119 #endif //_H_CSSMCERT