comparison src/pk/asn1/der/sequence/der_decode_sequence_multi.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05

Import of libtomcrypt 1.05
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 03:53:40 +0000
parents
children d5faf4814ddb
comparison
equal deleted inserted replaced
191:1c15b283127b 209:39d5d58461d6
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11 #include "tomcrypt.h"
12 #include <stdarg.h>
13
14
15 /**
16 @file der_decode_sequence_multi.c
17 ASN.1 DER, decode a SEQUENCE, Tom St Denis
18 */
19
20 #ifdef LTC_DER
21
22 int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
23 {
24 int err, type;
25 unsigned long size, x;
26 void *data;
27 va_list args;
28 ltc_asn1_list *list;
29
30 LTC_ARGCHK(in != NULL);
31
32 /* get size of output that will be required */
33 va_start(args, inlen);
34 x = 0;
35 for (;;) {
36 type = va_arg(args, int);
37 size = va_arg(args, unsigned long);
38 data = va_arg(args, void*);
39
40 if (type == LTC_ASN1_EOL) {
41 break;
42 }
43
44 switch (type) {
45 case LTC_ASN1_INTEGER:
46 case LTC_ASN1_SHORT_INTEGER:
47 case LTC_ASN1_BIT_STRING:
48 case LTC_ASN1_OCTET_STRING:
49 case LTC_ASN1_NULL:
50 case LTC_ASN1_OBJECT_IDENTIFIER:
51 case LTC_ASN1_IA5_STRING:
52 case LTC_ASN1_PRINTABLE_STRING:
53 case LTC_ASN1_UTCTIME:
54 case LTC_ASN1_SEQUENCE:
55 case LTC_ASN1_CHOICE:
56 ++x;
57 break;
58
59 default:
60 va_end(args);
61 return CRYPT_INVALID_ARG;
62 }
63 }
64 va_end(args);
65
66 /* allocate structure for x elements */
67 if (x == 0) {
68 return CRYPT_NOP;
69 }
70
71 list = XCALLOC(sizeof(*list), x);
72 if (list == NULL) {
73 return CRYPT_MEM;
74 }
75
76 /* fill in the structure */
77 va_start(args, inlen);
78 x = 0;
79 for (;;) {
80 type = va_arg(args, int);
81 size = va_arg(args, unsigned long);
82 data = va_arg(args, void*);
83
84 if (type == LTC_ASN1_EOL) {
85 break;
86 }
87
88 switch (type) {
89 case LTC_ASN1_INTEGER:
90 case LTC_ASN1_SHORT_INTEGER:
91 case LTC_ASN1_BIT_STRING:
92 case LTC_ASN1_OCTET_STRING:
93 case LTC_ASN1_NULL:
94 case LTC_ASN1_OBJECT_IDENTIFIER:
95 case LTC_ASN1_IA5_STRING:
96 case LTC_ASN1_PRINTABLE_STRING:
97 case LTC_ASN1_UTCTIME:
98 case LTC_ASN1_SEQUENCE:
99 case LTC_ASN1_CHOICE:
100 list[x].type = type;
101 list[x].size = size;
102 list[x++].data = data;
103 break;
104
105 default:
106 va_end(args);
107 err = CRYPT_INVALID_ARG;
108 goto LBL_ERR;
109 }
110 }
111 va_end(args);
112
113 err = der_decode_sequence(in, inlen, list, x);
114 LBL_ERR:
115 XFREE(list);
116 return err;
117 }
118
119 #endif
120
121
122 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_multi.c,v $ */
123 /* $Revision: 1.7 $ */
124 /* $Date: 2005/06/18 19:20:23 $ */