some more ASN.1 fixes

these should have been in #49
This commit is contained in:
Steffen Jaeckel 2014-08-31 18:26:14 +02:00
parent c342cb5a21
commit ee4c00b753
2 changed files with 20 additions and 9 deletions

View File

@ -519,7 +519,7 @@ int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
/* FLEXI DECODER handle unknown list decoder */
int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, ltc_asn1_list **out);
void der_free_sequence_flexi(ltc_asn1_list *list);
#define der_free_sequence_flexi der_sequence_free
void der_sequence_free(ltc_asn1_list *in);
/* BOOLEAN */

View File

@ -18,16 +18,17 @@
#ifdef LTC_DER
/**
Get the length of a DER sequence
Get the length of a DER sequence
@param list The sequences of items in the SEQUENCE
@param inlen The number of items
@param outlen [out] The length required in octets to store it
@param outlen [out] The length required in octets to store it
@return CRYPT_OK on success
*/
int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
unsigned long *outlen)
unsigned long *outlen)
{
int err, type;
int err;
ltc_asn1_type type;
unsigned long size, x, y, i;
void *data;
@ -41,7 +42,7 @@ int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
size = list[i].size;
data = list[i].data;
if (type == LTC_ASN1_EOL) {
if (type == LTC_ASN1_EOL) {
break;
}
@ -52,7 +53,7 @@ int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
}
y += x;
break;
case LTC_ASN1_INTEGER:
if ((err = der_length_integer(data, &x)) != CRYPT_OK) {
goto LBL_ERR;
@ -68,6 +69,7 @@ int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
break;
case LTC_ASN1_BIT_STRING:
case LTC_ASN1_RAW_BIT_STRING:
if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) {
goto LBL_ERR;
}
@ -99,6 +101,13 @@ int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
y += x;
break;
case LTC_ASN1_TELETEX_STRING:
if ((err = der_length_teletex_string(data, size, &x)) != CRYPT_OK) {
goto LBL_ERR;
}
y += x;
break;
case LTC_ASN1_PRINTABLE_STRING:
if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) {
goto LBL_ERR;
@ -129,8 +138,10 @@ int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
y += x;
break;
default:
case LTC_ASN1_CHOICE:
case LTC_ASN1_CONSTRUCTED:
case LTC_ASN1_EOL:
err = CRYPT_INVALID_ARG;
goto LBL_ERR;
}