2 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Free Software
5 * This file is part of LIBTASN1.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU 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, see <http://www.gnu.org/licenses/>.
23 /*****************************************************/
24 /* File: Test_tree.c */
25 /* Description: Test sequences for these functions: */
26 /* asn1_visit_tree, */
27 /* asn1_create_element, */
28 /* asn1_delete_structure, */
29 /* asn1_write_value, */
30 /* asn1_read_value, */
31 /*****************************************************/
41 main (int argc, char *argv[])
44 char buffer[10 * 1024];
45 ASN1_TYPE definitions = ASN1_TYPE_EMPTY;
46 ASN1_TYPE asn1_element = ASN1_TYPE_EMPTY;
47 char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
50 const char *treefile = getenv ("ASN1PKIX");
51 const char *indeffile = getenv ("ASN1INDEF");
54 treefile = "pkix.asn";
57 indeffile = "TestIndef.p12";
59 printf ("\n\n/****************************************/\n");
60 printf ("/* Test sequence : Test_indefinite */\n");
61 printf ("/****************************************/\n\n");
62 printf ("ASN1TREE: %s\n", treefile);
65 if (asn1_check_version ("0.2.11") == NULL)
66 printf ("\nLibrary version check ERROR:\n actual version: %s\n\n",
67 asn1_check_version (NULL));
69 result = asn1_parser2tree (treefile, &definitions, errorDescription);
70 if (result != ASN1_SUCCESS)
73 printf ("ErrorDescription = %s\n\n", errorDescription);
79 fd = fopen (indeffile, "rb");
82 printf ("Cannot read file %s\n", indeffile);
85 size = fread (buffer, 1, sizeof (buffer), fd);
88 printf ("Cannot read from file %s\n", indeffile);
95 asn1_create_element (definitions, "PKIX1.pkcs-12-PFX", &asn1_element);
96 if (result != ASN1_SUCCESS)
99 printf ("Cannot create PKCS12 element\n");
103 result = asn1_der_decoding (&asn1_element, buffer, size, errorDescription);
104 if (result != ASN1_SUCCESS)
106 asn1_perror (result);
107 printf ("Cannot decode BER data (size %d)\n", size);
111 /* Clear the definition structures */
112 asn1_delete_structure (&definitions);
113 asn1_delete_structure (&asn1_element);