1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
9 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
16 @file der_decode_sequence_multi.c
17 ASN.1 DER, decode a SEQUENCE, Tom St Denis
23 Decode a SEQUENCE type using a VA list
24 @param in Input buffer
25 @param inlen Length of input in octets
26 @remark <...> is of the form <type, size, data> (int, unsigned long, void*)
27 @return CRYPT_OK on success
29 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
32 unsigned long size, x;
37 LTC_ARGCHK(in != NULL);
39 /* get size of output that will be required */
40 va_start(args, inlen);
43 type = va_arg(args, int);
44 size = va_arg(args, unsigned long);
45 data = va_arg(args, void*);
47 if (type == LTC_ASN1_EOL) {
52 case LTC_ASN1_BOOLEAN:
53 case LTC_ASN1_INTEGER:
54 case LTC_ASN1_SHORT_INTEGER:
55 case LTC_ASN1_BIT_STRING:
56 case LTC_ASN1_OCTET_STRING:
58 case LTC_ASN1_OBJECT_IDENTIFIER:
59 case LTC_ASN1_IA5_STRING:
60 case LTC_ASN1_PRINTABLE_STRING:
61 case LTC_ASN1_UTF8_STRING:
62 case LTC_ASN1_UTCTIME:
65 case LTC_ASN1_SEQUENCE:
72 return CRYPT_INVALID_ARG;
77 /* allocate structure for x elements */
82 list = XCALLOC(sizeof(*list), x);
87 /* fill in the structure */
88 va_start(args, inlen);
91 type = va_arg(args, int);
92 size = va_arg(args, unsigned long);
93 data = va_arg(args, void*);
95 if (type == LTC_ASN1_EOL) {
100 case LTC_ASN1_BOOLEAN:
101 case LTC_ASN1_INTEGER:
102 case LTC_ASN1_SHORT_INTEGER:
103 case LTC_ASN1_BIT_STRING:
104 case LTC_ASN1_OCTET_STRING:
106 case LTC_ASN1_OBJECT_IDENTIFIER:
107 case LTC_ASN1_IA5_STRING:
108 case LTC_ASN1_PRINTABLE_STRING:
109 case LTC_ASN1_UTF8_STRING:
110 case LTC_ASN1_UTCTIME:
111 case LTC_ASN1_SEQUENCE:
114 case LTC_ASN1_CHOICE:
117 list[x++].data = data;
122 err = CRYPT_INVALID_ARG;
128 err = der_decode_sequence(in, inlen, list, x);
137 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_multi.c,v $ */
138 /* $Revision: 1.12 $ */
139 /* $Date: 2006/11/26 02:25:18 $ */