2 * Copyright (C) 2012-2014 Free Software Foundation, Inc.
4 * This file is part of LIBTASN1.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * Written by Simon Josefsson
38 static const struct tv tv[] = {
39 {ASN1_ETYPE_IA5_STRING, 20,
40 "\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72",
42 "\x16\x14\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72"},
43 {ASN1_ETYPE_PRINTABLE_STRING, 5, "\x4e\x69\x6b\x6f\x73",
44 7, "\x13\x05\x4e\x69\x6b\x6f\x73"},
45 {ASN1_ETYPE_UTF8_STRING, 12, "Αττική",
46 14, "\x0c\x0c\xce\x91\xcf\x84\xcf\x84\xce\xb9\xce\xba\xce\xae"},
47 {ASN1_ETYPE_TELETEX_STRING, 15,
48 "\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e",
50 "\x14\x0f\x53\x69\x6d\x6f\x6e\x20\x4a\x6f\x73\x65\x66\x73\x73\x6f\x6e"},
51 {ASN1_ETYPE_OCTET_STRING, 36,
52 "\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A",
54 "\x04\x24\x30\x22\x80\x0F\x32\x30\x31\x31\x30\x38\x32\x31\x30\x38\x30\x30\x30\x36\x5A\x81\x0F\x32\x30\x31\x31\x30\x38\x32\x33\x32\x30\x35\x39\x35\x39\x5A"}
58 main (int argc, char *argv[])
61 unsigned char tl[ASN1_MAX_TL_SIZE];
62 unsigned int tl_len, der_len, str_len;
63 const unsigned char *str;
68 for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
72 ret = asn1_encode_simple_der (tv[i].etype, tv[i].str, tv[i].str_len,
74 if (ret != ASN1_SUCCESS)
76 fprintf (stderr, "Encoding error in %u: %s\n", i,
80 der_len = tl_len + tv[i].str_len;
82 if (der_len != tv[i].der_len || memcmp (tl, tv[i].der, tl_len) != 0)
85 "DER encoding differs in %u! (size: %u, expected: %u)\n",
86 i, der_len, tv[i].der_len);
92 asn1_decode_simple_der (tv[i].etype, tv[i].der, tv[i].der_len, &str,
94 if (ret != ASN1_SUCCESS)
96 fprintf (stderr, "Decoding error in %u: %s\n", i,
101 if (str_len != tv[i].str_len || memcmp (str, tv[i].str, str_len) != 0)
104 "DER decoded data differ in %u! (size: %u, expected: %u)\n",
105 i, der_len, tv[i].str_len);