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
12 @file der_encode_ia5_string.c
13 ASN.1 DER, encode a IA5 STRING, Tom St Denis
20 @param in The array of IA5 to store (one per char)
21 @param inlen The number of IA5 to store
22 @param out [out] The destination for the DER encoded IA5 STRING
23 @param outlen [in/out] The max size and resulting size of the DER IA5 STRING
24 @return CRYPT_OK if successful
26 int der_encode_ia5_string(const unsigned char *in, unsigned long inlen,
27 unsigned char *out, unsigned long *outlen)
29 unsigned long x, y, len;
32 LTC_ARGCHK(in != NULL);
33 LTC_ARGCHK(out != NULL);
34 LTC_ARGCHK(outlen != NULL);
37 if ((err = der_length_ia5_string(in, inlen, &len)) != CRYPT_OK) {
44 return CRYPT_BUFFER_OVERFLOW;
47 /* encode the header+len */
51 out[x++] = (unsigned char)inlen;
52 } else if (inlen < 256) {
54 out[x++] = (unsigned char)inlen;
55 } else if (inlen < 65536UL) {
57 out[x++] = (unsigned char)((inlen>>8)&255);
58 out[x++] = (unsigned char)(inlen&255);
59 } else if (inlen < 16777216UL) {
61 out[x++] = (unsigned char)((inlen>>16)&255);
62 out[x++] = (unsigned char)((inlen>>8)&255);
63 out[x++] = (unsigned char)(inlen&255);
65 return CRYPT_INVALID_ARG;
69 for (y = 0; y < inlen; y++) {
70 out[x++] = der_ia5_char_encode(in[y]);
81 /* ref: $Format:%D$ */
82 /* git commit: $Format:%H$ */
83 /* commit time: $Format:%ai$ */