2 * Copyright (c) 2000-2002,2011,2014 Apple 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 * CLFieldsCommon.h - get/set/free routines common to certs and CRLs
23 #ifndef _CL_FIELDS_COMMON_H_
24 #define _CL_FIELDS_COMMON_H_
26 #include <Security/cssmtype.h>
27 #include <security_cdsa_utilities/cssmdata.h>
29 #include "DecodedItem.h"
31 #include <security_utilities/globalizer.h>
33 #include <Security/X509Templates.h>
40 * As of the NSS conversion, getField ops do NOT take a const
41 * DecodedItem argument since many of them use the DecodedItem's
42 * SecNssCoder for intermediate ops.
44 typedef bool (getItemFieldFcn
) (
46 unsigned index
, // which occurrence (0 = first)
47 uint32
&numFields
, // RETURNED
48 CssmOwnedData
&fieldValue
); // RETURNED
49 typedef void (setItemFieldFcn
) (
51 const CssmData
&fieldValue
);
52 typedef void (freeFieldFcn
) (
53 CssmOwnedData
&fieldValue
);
57 unsigned &nssObjLen
, // RETURNED
58 const SecAsn1Template
*&templ
); // RETURNED
61 * Routines for common validity checking for certificateToSign fields.
63 * Call from setField*: verify field isn't already set, optionally validate
68 const CssmData
&fieldValue
,
73 * Call from getField* for unique fields - detect missing field or
74 * index out of bounds.
77 const void *requiredField
,
80 /* common extension get/set/free */
81 void getFieldExtenCommon(
82 void *cdsaObj
, // e.g. CE_KeyUsage
83 // CSSM_DATA_PTR for berEncoded
84 const DecodedExten
&decodedExt
,
85 CssmOwnedData
&fieldValue
);
87 CSSM_X509_EXTENSION_PTR
verifySetFreeExtension(
88 const CssmData
&fieldValue
,
89 bool berEncoded
); // false: value in value.parsedValue
90 // true : value in BERValue
91 void freeFieldExtenCommon(
92 CSSM_X509_EXTENSION_PTR exten
,
96 * Common code for get/set subject/issuer name (C struct version)
98 bool getField_RDN_NSS (
99 const NSS_Name
&nssName
,
100 CssmOwnedData
&fieldValue
); // RETURNED
103 CssmOwnedData
&fieldValue
);
105 /* get normalized RDN */
106 bool getField_normRDN_NSS (
107 const CSSM_DATA
&derName
,
108 uint32
&numFields
, // RETURNED (if successful, 0 or 1)
109 CssmOwnedData
&fieldValue
); // RETURNED
112 * Common code for Time fields - Validity not before/after, this/next update
113 * Format: CSSM_X509_TIME
115 void freeField_Time (
116 CssmOwnedData
&fieldValue
);
118 bool getField_TimeNSS (
119 const NSS_Time
&derTime
,
120 unsigned index
, // which occurrence (0 = first)
121 uint32
&numFields
, // RETURNED
122 CssmOwnedData
&fieldValue
); // RETURNED
123 void setField_TimeNSS (
124 const CssmData
&fieldValue
,
128 void getField_AlgIdNSS (
129 const CSSM_X509_ALGORITHM_IDENTIFIER
&srcAlgId
,
130 CssmOwnedData
&fieldValue
); // RETURNED
131 void setField_AlgIdNSS (
132 const CssmData
&fieldValue
,
133 CSSM_X509_ALGORITHM_IDENTIFIER
&dstAlgId
,
136 void freeField_AlgId (
137 CssmOwnedData
&fieldValue
);
139 getItemFieldFcn getFieldUnknownExt
, getField_Unimplemented
;
140 setItemFieldFcn setFieldUnknownExt
, setField_ReadOnly
;
141 freeFieldFcn freeFieldUnknownExt
, freeFieldSimpleExtension
;
147 #endif /* _CL_FIELDS_COMMON_H_ */