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 Optimized ASN.1 DER decoder | 6 Optimized ASN.1 DER decoder |
7 | 7 |
8 */ | 8 */ |
9 | 9 |
10 #include "secerr.h" | 10 #include "secerr.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return SECSuccess; | 139 return SECSuccess; |
140 } | 140 } |
141 | 141 |
142 dest->data = definite_length_decoder(src->data, src->len, &dest->len, | 142 dest->data = definite_length_decoder(src->data, src->len, &dest->len, |
143 includeTag); | 143 includeTag); |
144 if (dest->data == NULL) | 144 if (dest->data == NULL) |
145 { | 145 { |
146 PORT_SetError(SEC_ERROR_BAD_DER); | 146 PORT_SetError(SEC_ERROR_BAD_DER); |
147 return SECFailure; | 147 return SECFailure; |
148 } | 148 } |
149 src->len -= (dest->data - src->data) + dest->len; | 149 src->len -= (int)(dest->data - src->data) + dest->len; |
150 src->data = dest->data + dest->len; | 150 src->data = dest->data + dest->len; |
151 return SECSuccess; | 151 return SECSuccess; |
152 } | 152 } |
153 | 153 |
154 /* check if the actual component's type matches the type in the template */ | 154 /* check if the actual component's type matches the type in the template */ |
155 | 155 |
156 static SECStatus MatchComponentType(const SEC_ASN1Template* templateEntry, | 156 static SECStatus MatchComponentType(const SEC_ASN1Template* templateEntry, |
157 SECItem* item, PRBool* match, void* dest) | 157 SECItem* item, PRBool* match, void* dest) |
158 { | 158 { |
159 unsigned long kind = 0; | 159 unsigned long kind = 0; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 disables type checking, and effectively forbids us from | 263 disables type checking, and effectively forbids us from |
264 transparently ignoring optional components we aren't aware of */ | 264 transparently ignoring optional components we aren't aware of */ |
265 *match = PR_TRUE; | 265 *match = PR_TRUE; |
266 return SECSuccess; | 266 return SECSuccess; |
267 } | 267 } |
268 | 268 |
269 /* first, do a class check */ | 269 /* first, do a class check */ |
270 if ( (tag & SEC_ASN1_CLASS_MASK) != | 270 if ( (tag & SEC_ASN1_CLASS_MASK) != |
271 (((unsigned char)kind) & SEC_ASN1_CLASS_MASK) ) | 271 (((unsigned char)kind) & SEC_ASN1_CLASS_MASK) ) |
272 { | 272 { |
273 #ifdef DEBUG | |
274 /* this is only to help debugging of the decoder in case of problems */ | 273 /* this is only to help debugging of the decoder in case of problems */ |
275 unsigned char tagclass = tag & SEC_ASN1_CLASS_MASK; | 274 /* unsigned char tagclass = tag & SEC_ASN1_CLASS_MASK; */ |
276 unsigned char expectedclass = (unsigned char)kind & SEC_ASN1_CLASS_MASK; | 275 /* unsigned char expectedclass = (unsigned char)kind & SEC_ASN1_CLASS_MA
SK; */ |
277 tagclass = tagclass; | |
278 expectedclass = expectedclass; | |
279 #endif | |
280 *match = PR_FALSE; | 276 *match = PR_FALSE; |
281 return SECSuccess; | 277 return SECSuccess; |
282 } | 278 } |
283 | 279 |
284 /* now do a tag check */ | 280 /* now do a tag check */ |
285 if ( ((unsigned char)kind & SEC_ASN1_TAGNUM_MASK) != | 281 if ( ((unsigned char)kind & SEC_ASN1_TAGNUM_MASK) != |
286 (tag & SEC_ASN1_TAGNUM_MASK)) | 282 (tag & SEC_ASN1_TAGNUM_MASK)) |
287 { | 283 { |
288 *match = PR_FALSE; | 284 *match = PR_FALSE; |
289 return SECSuccess; | 285 return SECSuccess; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 } | 646 } |
651 | 647 |
652 /* new decoder implementation. This is a recursive function */ | 648 /* new decoder implementation. This is a recursive function */ |
653 | 649 |
654 static SECStatus DecodeItem(void* dest, | 650 static SECStatus DecodeItem(void* dest, |
655 const SEC_ASN1Template* templateEntry, | 651 const SEC_ASN1Template* templateEntry, |
656 SECItem* src, PLArenaPool* arena, PRBool checkTag) | 652 SECItem* src, PLArenaPool* arena, PRBool checkTag) |
657 { | 653 { |
658 SECStatus rv = SECSuccess; | 654 SECStatus rv = SECSuccess; |
659 SECItem temp; | 655 SECItem temp; |
660 SECItem mark; | 656 SECItem mark = {siBuffer, NULL, 0}; |
661 PRBool pop = PR_FALSE; | 657 PRBool pop = PR_FALSE; |
662 PRBool decode = PR_TRUE; | 658 PRBool decode = PR_TRUE; |
663 PRBool save = PR_FALSE; | 659 PRBool save = PR_FALSE; |
664 unsigned long kind; | 660 unsigned long kind; |
665 PRBool match = PR_TRUE; | 661 PRBool match = PR_TRUE; |
666 PRBool optional = PR_FALSE; | |
667 | 662 |
668 PR_ASSERT(src && dest && templateEntry && arena); | 663 PR_ASSERT(src && dest && templateEntry && arena); |
669 #if 0 | 664 #if 0 |
670 if (!src || !dest || !templateEntry || !arena) | 665 if (!src || !dest || !templateEntry || !arena) |
671 { | 666 { |
672 PORT_SetError(SEC_ERROR_INVALID_ARGS); | 667 PORT_SetError(SEC_ERROR_INVALID_ARGS); |
673 rv = SECFailure; | 668 rv = SECFailure; |
674 } | 669 } |
675 #endif | 670 #endif |
676 | 671 |
677 if (SECSuccess == rv) | 672 if (SECSuccess == rv) |
678 { | 673 { |
679 /* do the template validation */ | 674 /* do the template validation */ |
680 kind = templateEntry->kind; | 675 kind = templateEntry->kind; |
681 optional = (0 != (kind & SEC_ASN1_OPTIONAL)); | |
682 if (!kind) | 676 if (!kind) |
683 { | 677 { |
684 PORT_SetError(SEC_ERROR_BAD_TEMPLATE); | 678 PORT_SetError(SEC_ERROR_BAD_TEMPLATE); |
685 rv = SECFailure; | 679 rv = SECFailure; |
686 } | 680 } |
687 } | 681 } |
688 | 682 |
689 if (SECSuccess == rv) | 683 if (SECSuccess == rv) |
690 { | 684 { |
691 #ifdef DEBUG | 685 #ifdef DEBUG |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 if (SECSuccess == rv && newsrc.len) | 937 if (SECSuccess == rv && newsrc.len) |
944 { | 938 { |
945 rv = SECFailure; | 939 rv = SECFailure; |
946 PORT_SetError(SEC_ERROR_EXTRA_INPUT); | 940 PORT_SetError(SEC_ERROR_EXTRA_INPUT); |
947 } | 941 } |
948 } | 942 } |
949 | 943 |
950 return rv; | 944 return rv; |
951 } | 945 } |
952 | 946 |
OLD | NEW |