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/>.
22 /*****************************************************/
23 /* File: Test_tree.c */
24 /* Description: Test sequences for these functions: */
25 /* asn1_visit_tree, */
26 /* asn1_create_element, */
27 /* asn1_delete_structure, */
28 /* asn1_write_value, */
29 /* asn1_read_value, */
30 /*****************************************************/
40 main (int argc, char *argv[])
43 char buffer[10 * 1024];
44 asn1_node definitions = NULL;
45 asn1_node asn1_element = NULL;
46 char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
49 const char *treefile = getenv ("ASN1PKIX");
50 const char *indeffile = getenv ("ASN1INDEF");
57 treefile = "pkix.asn";
60 indeffile = "TestIndef.p12";
64 printf ("\n\n/****************************************/\n");
65 printf ("/* Test sequence : Test_indefinite */\n");
66 printf ("/****************************************/\n\n");
67 printf ("ASN1TREE: %s\n", treefile);
71 if (asn1_check_version ("0.2.11") == NULL)
72 printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
73 asn1_check_version (NULL));
75 result = asn1_parser2tree (treefile, &definitions, errorDescription);
76 if (result != ASN1_SUCCESS)
79 printf ("ErrorDescription = %s\n\n", errorDescription);
85 fd = fopen (indeffile, "rb");
88 printf ("Cannot read file %s\n", indeffile);
91 size = fread (buffer, 1, sizeof (buffer), fd);
94 printf ("Cannot read from file %s\n", indeffile);
101 asn1_create_element (definitions, "PKIX1.pkcs-12-PFX", &asn1_element);
102 if (result != ASN1_SUCCESS)
104 asn1_perror (result);
105 printf ("Cannot create PKCS12 element\n");
109 result = asn1_der_decoding (&asn1_element, buffer, size, errorDescription);
110 if (result != ASN1_SUCCESS)
112 asn1_perror (result);
113 printf ("Cannot decode BER data (size %ld)\n", (long) size);
117 /* Clear the definition structures */
118 asn1_delete_structure (&definitions);
119 asn1_delete_structure (&asn1_element);