1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
14
/* allocate space for a PFX structure and set up initial
15
* arena pool. pfx structure is cleared and a pointer to
16
* the new structure is returned.
19
sec_pkcs12_new_pfx(void)
21
SEC_PKCS12PFXItem *pfx = NULL;
22
PLArenaPool *poolp = NULL;
24
poolp = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); /* XXX Different size? */
28
pfx = (SEC_PKCS12PFXItem *)PORT_ArenaZAlloc(poolp,
29
sizeof(SEC_PKCS12PFXItem));
37
PORT_FreeArena(poolp, PR_TRUE);
41
/* allocate space for a PFX structure and set up initial
42
* arena pool. pfx structure is cleared and a pointer to
43
* the new structure is returned.
45
SEC_PKCS12AuthenticatedSafe *
46
sec_pkcs12_new_asafe(PLArenaPool *poolp)
48
SEC_PKCS12AuthenticatedSafe *asafe = NULL;
51
mark = PORT_ArenaMark(poolp);
52
asafe = (SEC_PKCS12AuthenticatedSafe *)PORT_ArenaZAlloc(poolp,
53
sizeof(SEC_PKCS12AuthenticatedSafe));
57
PORT_Memset(&asafe->old_baggage, 0, sizeof(SEC_PKCS7ContentInfo));
59
PORT_ArenaUnmark(poolp, mark);
63
PORT_ArenaRelease(poolp, mark);
67
/* create a safe contents structure with a list of
68
* length 0 with the first element being NULL
70
SEC_PKCS12SafeContents *
71
sec_pkcs12_create_safe_contents(PLArenaPool *poolp)
73
SEC_PKCS12SafeContents *safe;
79
/* allocate structure */
80
mark = PORT_ArenaMark(poolp);
81
safe = (SEC_PKCS12SafeContents *)PORT_ArenaZAlloc(poolp,
82
sizeof(SEC_PKCS12SafeContents));
85
PORT_SetError(SEC_ERROR_NO_MEMORY);
86
PORT_ArenaRelease(poolp, mark);
91
safe->contents = (SEC_PKCS12SafeBag**)PORT_ArenaZAlloc(poolp,
92
sizeof(SEC_PKCS12SafeBag *));
93
if(safe->contents == NULL) {
94
PORT_SetError(SEC_ERROR_NO_MEMORY);
95
PORT_ArenaRelease(poolp, mark);
98
safe->contents[0] = NULL;
101
PORT_ArenaUnmark(poolp, mark);
105
/* create a new external bag which is appended onto the list
106
* of bags in baggage. the bag is created in the same arena
109
SEC_PKCS12BaggageItem *
110
sec_pkcs12_create_external_bag(SEC_PKCS12Baggage *luggage)
113
SEC_PKCS12BaggageItem *bag;
115
if(luggage == NULL) {
119
mark = PORT_ArenaMark(luggage->poolp);
121
/* allocate space for null terminated bag list */
122
if(luggage->bags == NULL) {
123
luggage->bags=(SEC_PKCS12BaggageItem**)PORT_ArenaZAlloc(luggage->poolp,
124
sizeof(SEC_PKCS12BaggageItem *));
125
if(luggage->bags == NULL) {
128
luggage->luggage_size = 0;
132
dummy = PORT_ArenaGrow(luggage->poolp, luggage->bags,
133
sizeof(SEC_PKCS12BaggageItem *) * (luggage->luggage_size + 1),
134
sizeof(SEC_PKCS12BaggageItem *) * (luggage->luggage_size + 2));
138
luggage->bags = (SEC_PKCS12BaggageItem**)dummy;
140
luggage->bags[luggage->luggage_size] =
141
(SEC_PKCS12BaggageItem *)PORT_ArenaZAlloc(luggage->poolp,
142
sizeof(SEC_PKCS12BaggageItem));
143
if(luggage->bags[luggage->luggage_size] == NULL) {
147
/* create new bag and append it to the end */
148
bag = luggage->bags[luggage->luggage_size];
149
bag->espvks = (SEC_PKCS12ESPVKItem **)PORT_ArenaZAlloc(
151
sizeof(SEC_PKCS12ESPVKItem *));
152
bag->unencSecrets = (SEC_PKCS12SafeBag **)PORT_ArenaZAlloc(
154
sizeof(SEC_PKCS12SafeBag *));
155
if((bag->espvks == NULL) || (bag->unencSecrets == NULL)) {
159
bag->poolp = luggage->poolp;
160
luggage->luggage_size++;
161
luggage->bags[luggage->luggage_size] = NULL;
162
bag->espvks[0] = NULL;
163
bag->unencSecrets[0] = NULL;
164
bag->nEspvks = bag->nSecrets = 0;
166
PORT_ArenaUnmark(luggage->poolp, mark);
170
PORT_ArenaRelease(luggage->poolp, mark);
171
PORT_SetError(SEC_ERROR_NO_MEMORY);
175
/* creates a baggage witha NULL terminated 0 length list */
177
sec_pkcs12_create_baggage(PLArenaPool *poolp)
179
SEC_PKCS12Baggage *luggage;
185
mark = PORT_ArenaMark(poolp);
188
luggage = (SEC_PKCS12Baggage *)PORT_ArenaZAlloc(poolp,
189
sizeof(SEC_PKCS12Baggage));
192
PORT_SetError(SEC_ERROR_NO_MEMORY);
193
PORT_ArenaRelease(poolp, mark);
198
luggage->bags = (SEC_PKCS12BaggageItem **)PORT_ArenaZAlloc(poolp,
199
sizeof(SEC_PKCS12BaggageItem *));
200
if(luggage->bags == NULL) {
201
PORT_SetError(SEC_ERROR_NO_MEMORY);
202
PORT_ArenaRelease(poolp, mark);
206
luggage->bags[0] = NULL;
207
luggage->luggage_size = 0;
208
luggage->poolp = poolp;
210
PORT_ArenaUnmark(poolp, mark);
214
/* free pfx structure and associated items in the arena */
216
SEC_PKCS12DestroyPFX(SEC_PKCS12PFXItem *pfx)
218
if (pfx != NULL && pfx->poolp != NULL)
220
PORT_FreeArena(pfx->poolp, PR_TRUE);