comparison libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_multi.c @ 302:973fccb59ea4 ucc-axis-hack

propagate from branch 'au.asn.ucc.matt.dropbear' (head 11034278bd1917bebcbdc69cf53b1891ce9db121) to branch 'au.asn.ucc.matt.dropbear.ucc-axis-hack' (head 10a1f614fec73d0820c3f61160d9db409b9beb46)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 12:59:58 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
299:740e782679be 302:973fccb59ea4
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 $ */