comparison src/pk/asn1/der/sequence/der_encode_sequence_multi.c @ 280:59400faa4b44 libtomcrypt-orig libtomcrypt-1.05

Re-import libtomcrypt 1.05 for cleaner propagating. From crypt-1.05.tar.bz2, SHA1 of 88250202bb51570dc64f7e8f1c943cda9479258f
author Matt Johnston <matt@ucc.asn.au>
date Wed, 08 Mar 2006 12:58:00 +0000
parents
children d5faf4814ddb
comparison
equal deleted inserted replaced
-1:000000000000 280:59400faa4b44
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_encode_sequence_multi.c
17 ASN.1 DER, encode a SEQUENCE, Tom St Denis
18 */
19
20 #ifdef LTC_DER
21
22 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
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(out != NULL);
31 LTC_ARGCHK(outlen != NULL);
32
33 /* get size of output that will be required */
34 va_start(args, outlen);
35 x = 0;
36 for (;;) {
37 type = va_arg(args, int);
38 size = va_arg(args, unsigned long);
39 data = va_arg(args, void*);
40
41 if (type == LTC_ASN1_EOL) {
42 break;
43 }
44
45 switch (type) {
46 case LTC_ASN1_INTEGER:
47 case LTC_ASN1_SHORT_INTEGER:
48 case LTC_ASN1_BIT_STRING:
49 case LTC_ASN1_OCTET_STRING:
50 case LTC_ASN1_NULL:
51 case LTC_ASN1_OBJECT_IDENTIFIER:
52 case LTC_ASN1_IA5_STRING:
53 case LTC_ASN1_PRINTABLE_STRING:
54 case LTC_ASN1_UTCTIME:
55 case LTC_ASN1_SEQUENCE:
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, outlen);
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 list[x].type = type;
100 list[x].size = size;
101 list[x++].data = data;
102 break;
103
104 default:
105 va_end(args);
106 err = CRYPT_INVALID_ARG;
107 goto LBL_ERR;
108 }
109 }
110 va_end(args);
111
112 err = der_encode_sequence(list, x, out, outlen);
113 LBL_ERR:
114 XFREE(list);
115 return err;
116 }
117
118 #endif
119
120
121 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence_multi.c,v $ */
122 /* $Revision: 1.6 $ */
123 /* $Date: 2005/06/18 19:20:23 $ */