Remove unused.
[libtasn1.git] / tests / Test_encoding.c
blob0a42543e55b526d9dfaf6311856eb527f18a2e0f
1 /*
2 * Copyright (C) 2006 Free Software Foundation
3 * Copyright (C) 2002 Fabio Fiorina
5 * This file is part of LIBTASN1.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
24 /******************************************************/
25 /* File: Test_encoding.c */
26 /* Description: Test writing values and DER encoding. */
27 /******************************************************/
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include "libtasn1.h"
35 unsigned char data[256];
36 int data_size = sizeof (data);
39 int
40 main (int argc, char *argv[])
42 asn1_retCode result;
43 ASN1_TYPE definitions = ASN1_TYPE_EMPTY;
44 ASN1_TYPE asn1_element = ASN1_TYPE_EMPTY;
45 char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
46 const char *treefile = getenv ("ASN1ENCODING");
48 if (!treefile)
49 treefile = "Test_encoding.asn";
51 printf ("\n\n/****************************************/\n");
52 printf ("/* Test sequence : coding-decoding */\n");
53 printf ("/****************************************/\n\n");
55 /* Check version */
56 if (asn1_check_version ("0.3.3") == NULL)
57 printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
58 asn1_check_version (NULL));
60 result = asn1_parser2tree (treefile, &definitions, errorDescription);
62 if (result != ASN1_SUCCESS)
64 libtasn1_perror (result);
65 printf ("ErrorDescription = %s\n\n", errorDescription);
66 exit (1);
69 result = asn1_create_element (definitions, "TEST_TREE.Koko", &asn1_element);
70 if (result != ASN1_SUCCESS)
72 fprintf (stderr, "asn1_create_element(): ");
73 libtasn1_perror (result);
74 exit (1);
77 result = asn1_write_value (asn1_element, "seqint", "NEW", 1);
78 if (result != ASN1_SUCCESS)
80 fprintf (stderr, "asn1_write_value(): seqint ");
81 libtasn1_perror (result);
82 exit (1);
85 result = asn1_write_value (asn1_element, "seqint.?LAST", "1234", 0);
86 if (result != ASN1_SUCCESS)
88 fprintf (stderr, "asn1_write_value(): seqint.?LAST ");
89 libtasn1_perror (result);
90 exit (1);
93 result = asn1_write_value (asn1_element, "int", "\x0f\xff\x01", 3);
94 if (result != ASN1_SUCCESS)
96 fprintf (stderr, "asn1_write_value(): int ");
97 libtasn1_perror (result);
98 exit (1);
101 result = asn1_write_value (asn1_element, "str", "string", 6);
102 if (result != ASN1_SUCCESS)
104 fprintf (stderr, "asn1_write_value(): str ");
105 libtasn1_perror (result);
106 exit (1);
109 /* Clear the definition structures */
110 asn1_delete_structure (&definitions);
112 result = asn1_der_coding (asn1_element, "", data, &data_size, NULL);
113 if (result != ASN1_SUCCESS)
115 fprintf (stderr, "Encoding error.\n");
116 libtasn1_perror (result);
117 exit (1);
120 result = asn1_der_decoding (&asn1_element, data, data_size, NULL);
121 if (result != ASN1_SUCCESS)
123 fprintf (stderr, "Decoding error.\n");
124 libtasn1_perror (result);
125 exit (1);
129 printf ("Success\n");
130 exit (0);