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_decode_ia5_string.c
13 ASN.1 DER, encode a IA5 STRING, Tom St Denis
21 @param in The DER encoded IA5 STRING
22 @param inlen The size of the DER IA5 STRING
23 @param out [out] The array of octets stored (one per char)
24 @param outlen [in/out] The number of octets stored
25 @return CRYPT_OK if successful
27 int der_decode_ia5_string(const unsigned char *in, unsigned long inlen,
28 unsigned char *out, unsigned long *outlen)
30 unsigned long x, y, len;
33 LTC_ARGCHK(in != NULL);
34 LTC_ARGCHK(out != NULL);
35 LTC_ARGCHK(outlen != NULL);
37 /* must have header at least */
39 return CRYPT_INVALID_PACKET;
43 if ((in[0] & 0x1F) != 0x16) {
44 return CRYPT_INVALID_PACKET;
48 /* decode the length */
50 /* valid # of bytes in length are 1,2,3 */
52 if ((y == 0) || (y > 3) || ((x + y) > inlen)) {
53 return CRYPT_INVALID_PACKET;
56 /* read the length in */
60 len = (len << 8) | in[x++];
69 return CRYPT_BUFFER_OVERFLOW;
72 if (len + x > inlen) {
73 return CRYPT_INVALID_PACKET;
77 for (y = 0; y < len; y++) {
78 t = der_ia5_value_decode(in[x++]);
80 return CRYPT_INVALID_ARG;
92 /* ref: $Format:%D$ */
93 /* git commit: $Format:%H$ */
94 /* commit time: $Format:%ai$ */