summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2014-08-20 16:19:22 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2014-08-20 16:19:22 +0200
commit241acd032783cabc7bf1ed8b8b432787dc2cf1c1 (patch)
tree05d749d25a558c810e65b87bc7ccf4d558cfe357
parentad2b479543a0bdfb51a456180cfda8644b4c872d (diff)
downloadlibtasn1-241acd032783cabc7bf1ed8b8b432787dc2cf1c1.tar.gz
tests: added additional test for the indefinite any tag
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/TestIndef3.derbin0 -> 660 bytes
-rw-r--r--tests/Test_indefinite.c49
3 files changed, 46 insertions, 6 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 144b321..639d9c0 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 coding-decoding2.asn \
- TestIndef2.p12
+ TestIndef2.p12 TestIndef3.der
# For crlf.
EXTRA_DIST += crlf.cer crl.der
@@ -51,6 +51,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/TestIndef3.der b/tests/TestIndef3.der
new file mode 100644
index 0000000..3ad5847
--- /dev/null
+++ b/tests/TestIndef3.der
Binary files differ
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);
}