diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-08-20 16:24:06 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-08-20 16:24:06 +0200 |
commit | 651b14b8670d43b561173b154ee35194e5585d32 (patch) | |
tree | eb68c5e239538ac89deaa19740cedf8c2ff4818d | |
parent | 7f21e2301d2ed2c63aa4adb02d1d02e31d8c2ca7 (diff) | |
download | libtasn1-651b14b8670d43b561173b154ee35194e5585d32.tar.gz |
backported test_indefinite
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/Test_indefinite.c | 49 |
2 files changed, 46 insertions, 6 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index a400af7..357fb50 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,7 +24,7 @@ LDADD = ../lib/libtasn1.la ../gl/libgnu.la EXTRA_DIST = Test_parser.asn Test_tree.asn Test_tree_asn1_tab.c \ Test_encoding.asn pkix.asn TestIndef.p12 choice.asn \ - TestIndef2.p12 + TestIndef2.p12 TestIndef3.der # For crlf. EXTRA_DIST += crlf.cer crl.der @@ -50,6 +50,7 @@ TESTS_ENVIRONMENT = \ ASN1CRLDER=$(srcdir)/crl.der \ ASN1INDEF=$(srcdir)/TestIndef.p12 \ ASN1INDEF2=$(srcdir)/TestIndef2.p12 \ + ASN1INDEF3=$(srcdir)/TestIndef3.der \ ASN1ENCODING=$(srcdir)/Test_encoding.asn \ THREADSAFETY_FILES=`find $(top_srcdir)/lib -name \*.c` \ EXEEXT=$(EXEEXT) \ diff --git a/tests/Test_indefinite.c b/tests/Test_indefinite.c index b1a435a..9f08793 100644 --- a/tests/Test_indefinite.c +++ b/tests/Test_indefinite.c @@ -49,6 +49,7 @@ main (int argc, char *argv[]) const char *treefile = getenv ("ASN1PKIX"); const char *indeffile = getenv ("ASN1INDEF"); const char *indeffile2 = getenv ("ASN1INDEF2"); + const char *indeffile3 = getenv ("ASN1INDEF3"); int verbose = 0; if (argc > 1) @@ -61,7 +62,10 @@ main (int argc, char *argv[]) indeffile = "TestIndef.p12"; if (!indeffile2) - indeffile = "TestIndef2.p12"; + indeffile2 = "TestIndef2.p12"; + + if (!indeffile3) + indeffile3 = "TestIndef3.der"; if (verbose) { @@ -114,7 +118,7 @@ main (int argc, char *argv[]) if (result != ASN1_SUCCESS) { asn1_perror (result); - printf ("Cannot decode BER data (size %ld) in %s\n", (long) size, indeffile); + printf ("Cannot decode BER data (size %ld) in %s: %s\n", (long) size, indeffile, errorDescription); exit (1); } @@ -124,13 +128,13 @@ main (int argc, char *argv[]) fd = fopen (indeffile2, "rb"); if (fd == NULL) { - printf ("Cannot read file %s\n", indeffile); + printf ("Cannot read file %s\n", indeffile2); exit (1); } size = fread (buffer, 1, sizeof (buffer), fd); if (size <= 0) { - printf ("Cannot read from file %s\n", indeffile); + printf ("Cannot read from file %s\n", indeffile2); exit (1); } @@ -149,7 +153,42 @@ main (int argc, char *argv[]) if (result != ASN1_SUCCESS) { asn1_perror (result); - printf ("Cannot decode BER data (size %ld) in %s\n", (long) size, indeffile2); + printf ("Cannot decode BER data (size %ld) in %s: %s\n", (long) size, indeffile2, errorDescription); + exit (1); + } + + asn1_delete_structure (&asn1_element); + + /* third test */ + fd = fopen (indeffile3, "rb"); + if (fd == NULL) + { + printf ("Cannot read file %s\n", indeffile3); + exit (1); + } + size = fread (buffer, 1, sizeof (buffer), fd); + if (size <= 0) + { + printf ("Cannot read from file %s\n", indeffile3); + exit (1); + } + + fclose (fd); + + result = + asn1_create_element (definitions, "PKIX1.pkcs-12-CertBag", &asn1_element); + if (result != ASN1_SUCCESS) + { + asn1_perror (result); + printf ("Cannot create CertBag element\n"); + exit (1); + } + + result = asn1_der_decoding (&asn1_element, buffer, size, errorDescription); + if (result != ASN1_SUCCESS) + { + asn1_perror (result); + printf ("Cannot decode DER data (size %ld) in %s: %s\n", (long) size, indeffile3, errorDescription); exit (1); } |