]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 | 1 | /* |
d8f41ccd | 2 | * Copyright (c) 2003-2004,2011,2014 Apple Inc. All Rights Reserved. |
b1ab9ed8 A |
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 | * pkcs12BagAttrs.h : internal representation of P12 SafeBag | |
26 | * attribute, OTHER THAN friendlyName and localKeyId. | |
27 | * This corresponds to a SecPkcs12AttrsRef at the | |
28 | * public API layer. | |
29 | */ | |
30 | ||
31 | #ifndef _PKCS12_BAG_ATTRS_H_ | |
32 | #define _PKCS12_BAG_ATTRS_H_ | |
33 | ||
34 | #include <Security/keyTemplates.h> // for NSS_Attribute | |
35 | #include <security_asn1/SecNssCoder.h> | |
36 | #include <CoreFoundation/CoreFoundation.h> | |
37 | ||
38 | class P12BagAttrs { | |
39 | public: | |
40 | /* | |
41 | * Empty constructor used by P12SafeBag during decoding. | |
42 | * Indivudual attrs not understood by P12SafeBag get added | |
43 | * via addAttr(). | |
44 | */ | |
45 | P12BagAttrs( | |
46 | SecNssCoder &coder) | |
47 | : mAttrs(NULL), | |
48 | mCoder(coder) { } | |
49 | ||
50 | /* | |
51 | * Copying constructor used by P12SafeBag during encoding. | |
52 | */ | |
53 | P12BagAttrs( | |
54 | const P12BagAttrs *otherAttrs, // optional | |
55 | SecNssCoder &coder); | |
56 | ||
57 | ~P12BagAttrs() { } | |
58 | ||
59 | /* Raw getter used just prior to encode. */ | |
60 | unsigned numAttrs() const; | |
61 | NSS_Attribute *getAttr( | |
62 | unsigned attrNum); | |
63 | ||
64 | /* | |
65 | * Add an attr during decoding. Only "generic" attrs, other | |
66 | * than friendlyName and localKeyId, are added here. | |
67 | */ | |
68 | void addAttr( | |
69 | const NSS_Attribute &attr); | |
70 | ||
71 | /* | |
72 | * Add an attr pre-encode, from SecPkcs12Add*() or | |
73 | * SecPkcs12AttrsAddAttr(). | |
74 | */ | |
75 | void addAttr( | |
76 | const CFDataRef attrOid, | |
77 | const CFArrayRef attrValues); | |
78 | ||
79 | /* | |
80 | * getter, public API version | |
81 | */ | |
82 | void getAttr( | |
83 | unsigned attrNum, | |
84 | CFDataRef *attrOid, // RETURNED | |
85 | CFArrayRef *attrValues); // RETURNED | |
86 | ||
87 | private: | |
88 | NSS_Attribute *reallocAttrs( | |
89 | size_t numNewAttrs); | |
90 | ||
91 | void copyAttr( | |
92 | const NSS_Attribute &src, | |
93 | NSS_Attribute &dst); | |
94 | ||
95 | /* | |
96 | * Stored in NSS form for easy encode | |
97 | */ | |
98 | NSS_Attribute **mAttrs; | |
99 | SecNssCoder &mCoder; | |
100 | }; | |
101 | ||
102 | /* | |
103 | * In the most common usage, a P12BagAttrs's SecNssCoder is associated | |
104 | * with the owning P12Coder's mCoder. In the case of a "standalone" | |
105 | * P12BagAttrs's created by the app via SecPkcs12AttrsCreate(), | |
106 | * this subclass is used, proving the P12BadAttr's SecNssCoder | |
107 | * directly. | |
108 | */ | |
109 | class P12BagAttrsStandAlone : public P12BagAttrs | |
110 | { | |
111 | public: | |
112 | P12BagAttrsStandAlone() | |
113 | : P12BagAttrs(mPrivCoder) | |
114 | { } | |
115 | ||
116 | ~P12BagAttrsStandAlone() { } | |
117 | ||
118 | private: | |
119 | SecNssCoder mPrivCoder; | |
120 | }; | |
121 | ||
122 | #endif /* _PKCS12_BAG_ATTRS_H_ */ | |
123 |