| 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 #include "secder.h" | 5 #include "secder.h" |
| 6 #include "secerr.h" | 6 #include "secerr.h" |
| 7 | 7 |
| 8 #if 0 | 8 #if 0 |
| 9 /* | 9 /* |
| 10 * Generic templates for individual/simple items. | 10 * Generic templates for individual/simple items. |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 return len; | 272 return len; |
| 273 } | 273 } |
| 274 | 274 |
| 275 | 275 |
| 276 static unsigned char * | 276 static unsigned char * |
| 277 der_encode(unsigned char *buf, DERTemplate *dtemplate, void *src) | 277 der_encode(unsigned char *buf, DERTemplate *dtemplate, void *src) |
| 278 { | 278 { |
| 279 int header_len; | 279 int header_len; |
| 280 PRUint32 contents_len; | 280 PRUint32 contents_len; |
| 281 unsigned long encode_kind, under_kind; | 281 unsigned long encode_kind, under_kind; |
| 282 PRBool explicit, optional, universal; | 282 PRBool explicit, universal; |
| 283 | 283 |
| 284 | 284 |
| 285 /* | 285 /* |
| 286 * First figure out how long the encoding will be. Do this by | 286 * First figure out how long the encoding will be. Do this by |
| 287 * traversing the template from top to bottom and accumulating | 287 * traversing the template from top to bottom and accumulating |
| 288 * the length of each leaf item. | 288 * the length of each leaf item. |
| 289 */ | 289 */ |
| 290 contents_len = contents_length (dtemplate, src); | 290 contents_len = contents_length (dtemplate, src); |
| 291 header_len = header_length (dtemplate, contents_len); | 291 header_len = header_length (dtemplate, contents_len); |
| 292 | 292 |
| 293 /* | 293 /* |
| 294 * Enough smarts was involved already, so that if both the | 294 * Enough smarts was involved already, so that if both the |
| 295 * header and the contents have a length of zero, then we | 295 * header and the contents have a length of zero, then we |
| 296 * are not doing any encoding for this element. | 296 * are not doing any encoding for this element. |
| 297 */ | 297 */ |
| 298 if (header_len == 0 && contents_len == 0) | 298 if (header_len == 0 && contents_len == 0) |
| 299 return buf; | 299 return buf; |
| 300 | 300 |
| 301 encode_kind = dtemplate->kind; | 301 encode_kind = dtemplate->kind; |
| 302 | 302 |
| 303 explicit = (encode_kind & DER_EXPLICIT) ? PR_TRUE : PR_FALSE; | 303 explicit = (encode_kind & DER_EXPLICIT) ? PR_TRUE : PR_FALSE; |
| 304 optional = (encode_kind & DER_OPTIONAL) ? PR_TRUE : PR_FALSE; | |
| 305 encode_kind &= ~DER_OPTIONAL; | 304 encode_kind &= ~DER_OPTIONAL; |
| 306 universal = ((encode_kind & DER_CLASS_MASK) == DER_UNIVERSAL) | 305 universal = ((encode_kind & DER_CLASS_MASK) == DER_UNIVERSAL) |
| 307 ? PR_TRUE : PR_FALSE; | 306 ? PR_TRUE : PR_FALSE; |
| 308 | 307 |
| 309 if (encode_kind & DER_POINTER) { | 308 if (encode_kind & DER_POINTER) { |
| 310 if (contents_len) { | 309 if (contents_len) { |
| 311 src = *(void **)src; | 310 src = *(void **)src; |
| 312 PORT_Assert (src != NULL); | 311 PORT_Assert (src != NULL); |
| 313 } | 312 } |
| 314 if (dtemplate->sub != NULL) { | 313 if (dtemplate->sub != NULL) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (dest->data == NULL) { | 463 if (dest->data == NULL) { |
| 465 PORT_SetError(SEC_ERROR_NO_MEMORY); | 464 PORT_SetError(SEC_ERROR_NO_MEMORY); |
| 466 return SECFailure; | 465 return SECFailure; |
| 467 } | 466 } |
| 468 | 467 |
| 469 /* Now encode into the buffer */ | 468 /* Now encode into the buffer */ |
| 470 (void) der_encode (dest->data, dtemplate, src); | 469 (void) der_encode (dest->data, dtemplate, src); |
| 471 | 470 |
| 472 return SECSuccess; | 471 return SECSuccess; |
| 473 } | 472 } |
| OLD | NEW |