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_encode_sequence_multi.c
17 ASN.1 DER, encode a SEQUENCE, Tom St Denis
23 Encode a SEQUENCE type using a VA list
24 @param out [out] Destination for data
25 @param outlen [in/out] Length of buffer and resulting length of output
26 @remark <...> is of the form <type, size, data> (int, unsigned long, void*)
27 @return CRYPT_OK on success
29 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
32 unsigned long size, x;
37 LTC_ARGCHK(out != NULL);
38 LTC_ARGCHK(outlen != NULL);
40 /* get size of output that will be required */
41 va_start(args, outlen);
44 type = va_arg(args, int);
45 size = va_arg(args, unsigned long);
46 data = va_arg(args, void*);
48 if (type == LTC_ASN1_EOL) {
53 case LTC_ASN1_BOOLEAN:
54 case LTC_ASN1_INTEGER:
55 case LTC_ASN1_SHORT_INTEGER:
56 case LTC_ASN1_BIT_STRING:
57 case LTC_ASN1_OCTET_STRING:
59 case LTC_ASN1_OBJECT_IDENTIFIER:
60 case LTC_ASN1_IA5_STRING:
61 case LTC_ASN1_PRINTABLE_STRING:
62 case LTC_ASN1_UTF8_STRING:
63 case LTC_ASN1_UTCTIME:
64 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, outlen);
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:
116 list[x++].data = data;
121 err = CRYPT_INVALID_ARG;
127 err = der_encode_sequence(list, x, out, outlen);
136 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence_multi.c,v $ */
137 /* $Revision: 1.11 $ */
138 /* $Date: 2006/11/26 02:25:18 $ */