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
24
/******************************************************/
25
/* File: Test_encoding.c */
26
/* Description: Test writing values and DER encoding. */
27
/******************************************************/
35
unsigned char data[256];
36
int data_size = sizeof (data);
40
main (int argc, char *argv[])
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");
49
treefile = "Test_encoding.asn";
51
printf ("\n\n/****************************************/\n");
52
printf ("/* Test sequence : coding-decoding */\n");
53
printf ("/****************************************/\n\n");
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);
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);
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);
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);
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);
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);
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);
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);
129
printf ("Success\n");