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
14 @file der_encode_sequence_multi.c
15 ASN.1 DER, encode a SEQUENCE, Tom St Denis
21 Encode a SEQUENCE type using a VA list
22 @param out [out] Destination for data
23 @param outlen [in/out] Length of buffer and resulting length of output
24 @remark <...> is of the form <type, size, data> (int, unsigned long, void*)
25 @return CRYPT_OK on success
27 int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
31 unsigned long size, x;
36 LTC_ARGCHK(out != NULL);
37 LTC_ARGCHK(outlen != NULL);
39 /* get size of output that will be required */
40 va_start(args, outlen);
43 type = (ltc_asn1_type)va_arg(args, int);
44 size = va_arg(args, unsigned long);
45 data = va_arg(args, void*);
46 LTC_UNUSED_PARAM(size);
47 LTC_UNUSED_PARAM(data);
49 if (type == LTC_ASN1_EOL) {
54 case LTC_ASN1_BOOLEAN:
55 case LTC_ASN1_INTEGER:
56 case LTC_ASN1_SHORT_INTEGER:
57 case LTC_ASN1_BIT_STRING:
58 case LTC_ASN1_OCTET_STRING:
60 case LTC_ASN1_OBJECT_IDENTIFIER:
61 case LTC_ASN1_IA5_STRING:
62 case LTC_ASN1_PRINTABLE_STRING:
63 case LTC_ASN1_UTF8_STRING:
64 case LTC_ASN1_UTCTIME:
65 case LTC_ASN1_SEQUENCE:
68 case LTC_ASN1_RAW_BIT_STRING:
69 case LTC_ASN1_GENERALIZEDTIME:
74 case LTC_ASN1_CONSTRUCTED:
75 case LTC_ASN1_CONTEXT_SPECIFIC:
77 case LTC_ASN1_TELETEX_STRING:
79 return CRYPT_INVALID_ARG;
84 /* allocate structure for x elements */
89 list = XCALLOC(sizeof(*list), x);
94 /* fill in the structure */
95 va_start(args, outlen);
98 type = (ltc_asn1_type)va_arg(args, int);
99 size = va_arg(args, unsigned long);
100 data = va_arg(args, void*);
102 if (type == LTC_ASN1_EOL) {
107 case LTC_ASN1_BOOLEAN:
108 case LTC_ASN1_INTEGER:
109 case LTC_ASN1_SHORT_INTEGER:
110 case LTC_ASN1_BIT_STRING:
111 case LTC_ASN1_OCTET_STRING:
113 case LTC_ASN1_OBJECT_IDENTIFIER:
114 case LTC_ASN1_IA5_STRING:
115 case LTC_ASN1_PRINTABLE_STRING:
116 case LTC_ASN1_UTF8_STRING:
117 case LTC_ASN1_UTCTIME:
118 case LTC_ASN1_SEQUENCE:
121 case LTC_ASN1_RAW_BIT_STRING:
122 case LTC_ASN1_GENERALIZEDTIME:
123 LTC_SET_ASN1(list, x++, type, data, size);
126 case LTC_ASN1_CHOICE:
127 case LTC_ASN1_CONSTRUCTED:
128 case LTC_ASN1_CONTEXT_SPECIFIC:
130 case LTC_ASN1_TELETEX_STRING:
132 err = CRYPT_INVALID_ARG;
138 err = der_encode_sequence(list, x, out, outlen);
147 /* ref: $Format:%D$ */
148 /* git commit: $Format:%H$ */
149 /* commit time: $Format:%ai$ */