2 * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // cssmcert - CSSM layer certificate (CL) related objects.
25 #include <Security/utilities.h>
26 #include <Security/cssmalloc.h>
33 // A CSSM_FIELD, essentially an OID/Data pair.
35 class CssmField
: public PodWrapper
<CssmField
, CSSM_FIELD
> {
38 CssmField(const CSSM_OID
&oid
, const CSSM_DATA
&value
)
39 { FieldOid
= oid
; FieldValue
= value
; }
41 CssmField(const CSSM_OID
&oid
)
42 { FieldOid
= oid
; FieldValue
= CssmData(); }
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
); }
50 bool isComplex() const
51 { return value().length() == CSSM_FIELDVALUE_COMPLEX_DATA_TYPE
; }
56 // An encoded certificate
58 class EncodedCertificate
: public PodWrapper
<EncodedCertificate
, CSSM_ENCODED_CERT
> {
60 EncodedCertificate(CSSM_CERT_TYPE type
= CSSM_CERT_UNKNOWN
,
61 CSSM_CERT_ENCODING enc
= CSSM_CERT_ENCODING_UNKNOWN
,
62 const CSSM_DATA
*data
= NULL
);
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
); }
68 // CssmDataoid features
69 void *data() const { return blob().data(); }
70 size_t length() const { return blob().length(); }
75 // CertGroups - groups of certificates in a bewildering variety of forms
77 class CertGroup
: public PodWrapper
<CertGroup
, CSSM_CERTGROUP
> {
80 CertGroup(CSSM_CERT_TYPE ctype
, CSSM_CERT_ENCODING encoding
, CSSM_CERTGROUP_TYPE type
);
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
; }
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
); }
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
); }
103 // free all memory in this group with the given allocator
104 void destroy(CssmAllocator
&allocator
);
111 namespace DataWalkers
{
116 } // end namespace DataWalkers
117 } // end namespace Security