OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 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 | 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/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 /* | 5 /* |
6 * Support routines for SECItem data structure. | 6 * Support routines for SECItem data structure. |
7 */ | 7 */ |
8 | 8 |
9 #include "seccomon.h" | 9 #include "seccomon.h" |
10 #include "secitem.h" | 10 #include "secitem.h" |
11 #include "base64.h" | 11 #include "base64.h" |
12 #include "secerr.h" | 12 #include "secerr.h" |
13 #include "secport.h" | 13 #include "secport.h" |
14 | 14 |
15 SECItem * | 15 SECItem * |
16 SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, unsigned int len) | 16 SECITEM_AllocItem(PLArenaPool *arena, SECItem *item, unsigned int len) |
17 { | 17 { |
18 SECItem *result = NULL; | 18 SECItem *result = NULL; |
19 void *mark = NULL; | 19 void *mark = NULL; |
20 | 20 |
21 if (arena != NULL) { | 21 if (arena != NULL) { |
22 mark = PORT_ArenaMark(arena); | 22 mark = PORT_ArenaMark(arena); |
23 } | 23 } |
24 | 24 |
25 if (item == NULL) { | 25 if (item == NULL) { |
26 if (arena != NULL) { | 26 if (arena != NULL) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 /* | 71 /* |
72 * If item is not NULL, the above has set item->data and | 72 * If item is not NULL, the above has set item->data and |
73 * item->len to 0. | 73 * item->len to 0. |
74 */ | 74 */ |
75 } | 75 } |
76 return(NULL); | 76 return(NULL); |
77 } | 77 } |
78 | 78 |
79 SECStatus | 79 SECStatus |
80 SECITEM_ReallocItem(PRArenaPool *arena, SECItem *item, unsigned int oldlen, | 80 SECITEM_ReallocItem(PLArenaPool *arena, SECItem *item, unsigned int oldlen, |
81 unsigned int newlen) | 81 unsigned int newlen) |
82 { | 82 { |
83 PORT_Assert(item != NULL); | 83 PORT_Assert(item != NULL); |
84 if (item == NULL) { | 84 if (item == NULL) { |
85 /* XXX Set error. But to what? */ | 85 /* XXX Set error. But to what? */ |
86 return SECFailure; | 86 return SECFailure; |
87 } | 87 } |
88 | 88 |
89 /* | 89 /* |
90 * If no old length, degenerate to just plain alloc. | 90 * If no old length, degenerate to just plain alloc. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 return (PRBool)!PORT_Memcmp(a->data, b->data, a->len); | 158 return (PRBool)!PORT_Memcmp(a->data, b->data, a->len); |
159 } | 159 } |
160 | 160 |
161 SECItem * | 161 SECItem * |
162 SECITEM_DupItem(const SECItem *from) | 162 SECITEM_DupItem(const SECItem *from) |
163 { | 163 { |
164 return SECITEM_ArenaDupItem(NULL, from); | 164 return SECITEM_ArenaDupItem(NULL, from); |
165 } | 165 } |
166 | 166 |
167 SECItem * | 167 SECItem * |
168 SECITEM_ArenaDupItem(PRArenaPool *arena, const SECItem *from) | 168 SECITEM_ArenaDupItem(PLArenaPool *arena, const SECItem *from) |
169 { | 169 { |
170 SECItem *to; | 170 SECItem *to; |
171 | 171 |
172 if ( from == NULL ) { | 172 if ( from == NULL ) { |
173 return(NULL); | 173 return(NULL); |
174 } | 174 } |
175 | 175 |
176 if ( arena != NULL ) { | 176 if ( arena != NULL ) { |
177 to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem)); | 177 to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem)); |
178 } else { | 178 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
195 to->len = from->len; | 195 to->len = from->len; |
196 to->type = from->type; | 196 to->type = from->type; |
197 if ( to->len ) { | 197 if ( to->len ) { |
198 PORT_Memcpy(to->data, from->data, to->len); | 198 PORT_Memcpy(to->data, from->data, to->len); |
199 } | 199 } |
200 | 200 |
201 return(to); | 201 return(to); |
202 } | 202 } |
203 | 203 |
204 SECStatus | 204 SECStatus |
205 SECITEM_CopyItem(PRArenaPool *arena, SECItem *to, const SECItem *from) | 205 SECITEM_CopyItem(PLArenaPool *arena, SECItem *to, const SECItem *from) |
206 { | 206 { |
207 to->type = from->type; | 207 to->type = from->type; |
208 if (from->data && from->len) { | 208 if (from->data && from->len) { |
209 if ( arena ) { | 209 if ( arena ) { |
210 to->data = (unsigned char*) PORT_ArenaAlloc(arena, from->len); | 210 to->data = (unsigned char*) PORT_ArenaAlloc(arena, from->len); |
211 } else { | 211 } else { |
212 to->data = (unsigned char*) PORT_Alloc(from->len); | 212 to->data = (unsigned char*) PORT_Alloc(from->len); |
213 } | 213 } |
214 | 214 |
215 if (!to->data) { | 215 if (!to->data) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 SECStatus rv = SECITEM_CopyItem(arena, | 412 SECStatus rv = SECITEM_CopyItem(arena, |
413 &result->items[i], &from->items[i]); | 413 &result->items[i], &from->items[i]); |
414 if (rv != SECSuccess) { | 414 if (rv != SECSuccess) { |
415 SECITEM_ZfreeArray(result, PR_TRUE); | 415 SECITEM_ZfreeArray(result, PR_TRUE); |
416 return NULL; | 416 return NULL; |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 return result; | 420 return result; |
421 } | 421 } |
OLD | NEW |