2 * Copyright (C) 2002-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/>.
21 /******************************************************/
22 /* File: Test_encoding.c */
23 /* Description: Test writing values and DER encoding. */
24 /******************************************************/
32 unsigned char data[256];
33 int data_size = sizeof (data);
37 main (int argc, char *argv[])
39 int result, verbose = 0;
40 asn1_node definitions = NULL;
41 asn1_node asn1_element = NULL;
42 char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
43 const char *treefile = getenv ("ASN1ENCODING");
49 treefile = "Test_encoding.asn";
53 printf ("\n\n/****************************************/\n");
54 printf ("/* Test sequence : coding-decoding */\n");
55 printf ("/****************************************/\n\n");
59 if (asn1_check_version ("0.3.3") == NULL)
60 printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
61 asn1_check_version (NULL));
63 result = asn1_parser2tree (treefile, &definitions, errorDescription);
65 if (result != ASN1_SUCCESS)
68 printf ("ErrorDescription = %s\n\n", errorDescription);
72 result = asn1_create_element (definitions, "TEST_TREE.Koko", &asn1_element);
73 if (result != ASN1_SUCCESS)
75 fprintf (stderr, "asn1_create_element(): ");
80 result = asn1_write_value (asn1_element, "seqint", "NEW", 1);
81 if (result != ASN1_SUCCESS)
83 fprintf (stderr, "asn1_write_value(): seqint ");
88 result = asn1_write_value (asn1_element, "seqint.?LAST", "1234", 0);
89 if (result != ASN1_SUCCESS)
91 fprintf (stderr, "asn1_write_value(): seqint.?LAST ");
96 result = asn1_write_value (asn1_element, "int", "\x0f\xff\x01", 3);
97 if (result != ASN1_SUCCESS)
99 fprintf (stderr, "asn1_write_value(): int ");
100 asn1_perror (result);
104 result = asn1_write_value (asn1_element, "str", "string", 6);
105 if (result != ASN1_SUCCESS)
107 fprintf (stderr, "asn1_write_value(): str ");
108 asn1_perror (result);
112 /* Clear the definition structures */
113 asn1_delete_structure (&definitions);
115 result = asn1_der_coding (asn1_element, "", data, &data_size, NULL);
116 if (result != ASN1_SUCCESS)
118 fprintf (stderr, "Encoding error.\n");
119 asn1_perror (result);
123 result = asn1_der_decoding (&asn1_element, data, data_size, NULL);
124 if (result != ASN1_SUCCESS)
126 fprintf (stderr, "Decoding error.\n");
127 asn1_perror (result);
131 asn1_delete_structure (&asn1_element);
134 printf ("Success\n");