2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is the Netscape security libraries.
14
* The Initial Developer of the Original Code is Netscape
15
* Communications Corporation. Portions created by Netscape are
16
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
21
* Alternatively, the contents of this file may be used under the
22
* terms of the GNU General Public License Version 2 or later (the
23
* "GPL"), in which case the provisions of the GPL are applicable
24
* instead of those above. If you wish to allow use of your
25
* version of this file only under the terms of the GPL and not to
26
* allow others to use your version of this file under the MPL,
27
* indicate your decision by deleting the provisions above and
28
* replace them with the notice and other provisions required by
29
* the GPL. If you do not delete the provisions above, a recipient
30
* may use your version of this file under either the MPL or the
43
/* allocate space for a PFX structure and set up initial
44
* arena pool. pfx structure is cleared and a pointer to
45
* the new structure is returned.
48
sec_pkcs12_new_pfx(void)
50
SEC_PKCS12PFXItem *pfx = NULL;
51
PRArenaPool *poolp = NULL;
53
poolp = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); /* XXX Different size? */
57
pfx = (SEC_PKCS12PFXItem *)PORT_ArenaZAlloc(poolp,
58
sizeof(SEC_PKCS12PFXItem));
66
PORT_FreeArena(poolp, PR_TRUE);
70
/* allocate space for a PFX structure and set up initial
71
* arena pool. pfx structure is cleared and a pointer to
72
* the new structure is returned.
74
SEC_PKCS12AuthenticatedSafe *
75
sec_pkcs12_new_asafe(PRArenaPool *poolp)
77
SEC_PKCS12AuthenticatedSafe *asafe = NULL;
80
mark = PORT_ArenaMark(poolp);
81
asafe = (SEC_PKCS12AuthenticatedSafe *)PORT_ArenaZAlloc(poolp,
82
sizeof(SEC_PKCS12AuthenticatedSafe));
86
PORT_Memset(&asafe->old_baggage, 0, sizeof(SEC_PKCS7ContentInfo));
88
PORT_ArenaUnmark(poolp, mark);
92
PORT_ArenaRelease(poolp, mark);
96
/* create a safe contents structure with a list of
97
* length 0 with the first element being NULL
99
SEC_PKCS12SafeContents *
100
sec_pkcs12_create_safe_contents(PRArenaPool *poolp)
102
SEC_PKCS12SafeContents *safe;
108
/* allocate structure */
109
mark = PORT_ArenaMark(poolp);
110
safe = (SEC_PKCS12SafeContents *)PORT_ArenaZAlloc(poolp,
111
sizeof(SEC_PKCS12SafeContents));
114
PORT_SetError(SEC_ERROR_NO_MEMORY);
115
PORT_ArenaRelease(poolp, mark);
120
safe->contents = (SEC_PKCS12SafeBag**)PORT_ArenaZAlloc(poolp,
121
sizeof(SEC_PKCS12SafeBag *));
122
if(safe->contents == NULL) {
123
PORT_SetError(SEC_ERROR_NO_MEMORY);
124
PORT_ArenaRelease(poolp, mark);
127
safe->contents[0] = NULL;
130
PORT_ArenaUnmark(poolp, mark);
134
/* create a new external bag which is appended onto the list
135
* of bags in baggage. the bag is created in the same arena
138
SEC_PKCS12BaggageItem *
139
sec_pkcs12_create_external_bag(SEC_PKCS12Baggage *luggage)
142
SEC_PKCS12BaggageItem *bag;
144
if(luggage == NULL) {
148
mark = PORT_ArenaMark(luggage->poolp);
150
/* allocate space for null terminated bag list */
151
if(luggage->bags == NULL) {
152
luggage->bags=(SEC_PKCS12BaggageItem**)PORT_ArenaZAlloc(luggage->poolp,
153
sizeof(SEC_PKCS12BaggageItem *));
154
if(luggage->bags == NULL) {
157
luggage->luggage_size = 0;
161
dummy = PORT_ArenaGrow(luggage->poolp, luggage->bags,
162
sizeof(SEC_PKCS12BaggageItem *) * (luggage->luggage_size + 1),
163
sizeof(SEC_PKCS12BaggageItem *) * (luggage->luggage_size + 2));
167
luggage->bags = (SEC_PKCS12BaggageItem**)dummy;
169
luggage->bags[luggage->luggage_size] =
170
(SEC_PKCS12BaggageItem *)PORT_ArenaZAlloc(luggage->poolp,
171
sizeof(SEC_PKCS12BaggageItem));
172
if(luggage->bags[luggage->luggage_size] == NULL) {
176
/* create new bag and append it to the end */
177
bag = luggage->bags[luggage->luggage_size];
178
bag->espvks = (SEC_PKCS12ESPVKItem **)PORT_ArenaZAlloc(
180
sizeof(SEC_PKCS12ESPVKItem *));
181
bag->unencSecrets = (SEC_PKCS12SafeBag **)PORT_ArenaZAlloc(
183
sizeof(SEC_PKCS12SafeBag *));
184
if((bag->espvks == NULL) || (bag->unencSecrets == NULL)) {
188
bag->poolp = luggage->poolp;
189
luggage->luggage_size++;
190
luggage->bags[luggage->luggage_size] = NULL;
191
bag->espvks[0] = NULL;
192
bag->unencSecrets[0] = NULL;
193
bag->nEspvks = bag->nSecrets = 0;
195
PORT_ArenaUnmark(luggage->poolp, mark);
199
PORT_ArenaRelease(luggage->poolp, mark);
200
PORT_SetError(SEC_ERROR_NO_MEMORY);
204
/* creates a baggage witha NULL terminated 0 length list */
206
sec_pkcs12_create_baggage(PRArenaPool *poolp)
208
SEC_PKCS12Baggage *luggage;
214
mark = PORT_ArenaMark(poolp);
217
luggage = (SEC_PKCS12Baggage *)PORT_ArenaZAlloc(poolp,
218
sizeof(SEC_PKCS12Baggage));
221
PORT_SetError(SEC_ERROR_NO_MEMORY);
222
PORT_ArenaRelease(poolp, mark);
227
luggage->bags = (SEC_PKCS12BaggageItem **)PORT_ArenaZAlloc(poolp,
228
sizeof(SEC_PKCS12BaggageItem *));
229
if(luggage->bags == NULL) {
230
PORT_SetError(SEC_ERROR_NO_MEMORY);
231
PORT_ArenaRelease(poolp, mark);
235
luggage->bags[0] = NULL;
236
luggage->luggage_size = 0;
237
luggage->poolp = poolp;
239
PORT_ArenaUnmark(poolp, mark);
243
/* free pfx structure and associated items in the arena */
245
SEC_PKCS12DestroyPFX(SEC_PKCS12PFXItem *pfx)
247
if (pfx != NULL && pfx->poolp != NULL)
249
PORT_FreeArena(pfx->poolp, PR_TRUE);