diff options
author | sangsu <sangsu.choi@samsung.com> | 2016-06-08 10:17:41 +0900 |
---|---|---|
committer | sangsu <sangsu.choi@samsung.com> | 2016-06-08 10:18:15 +0900 |
commit | a39386a3afe2d7e0cc717a49f970f53d974fda53 (patch) | |
tree | d6deb781410d96006a58fcfcaa8f31ffcc139523 /tests/Test_choice_ocsp.c | |
parent | d2521ee04e00e1c060001d5d67c1cf0bd23ec260 (diff) | |
download | libtasn1-a39386a3afe2d7e0cc717a49f970f53d974fda53.tar.gz libtasn1-a39386a3afe2d7e0cc717a49f970f53d974fda53.tar.bz2 libtasn1-a39386a3afe2d7e0cc717a49f970f53d974fda53.zip |
Imported Upstream version 4.8upstream/4.8submit/upstream/20160613.071414
Change-Id: I25e57ece28b9ebb637a2b7356f57e11b7f2eb807
Signed-off-by: sangsu <sangsu.choi@samsung.com>
Diffstat (limited to 'tests/Test_choice_ocsp.c')
-rw-r--r-- | tests/Test_choice_ocsp.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/Test_choice_ocsp.c b/tests/Test_choice_ocsp.c new file mode 100644 index 0000000..d4183b6 --- /dev/null +++ b/tests/Test_choice_ocsp.c @@ -0,0 +1,80 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <libtasn1.h> + +int +main (int argc, char** argv) +{ + int result = 0, len; + asn1_node definitions = NULL, node1 = NULL; + char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; + const char *choicefile = getenv ("ASN1CHOICE_OCSP"); + const char *datafile = getenv ("ASN1CHOICE_OCSP_DATA"); + FILE *fp; + char data[1024]; + char data2[1024]; + int data_size = sizeof (data); + + if (!choicefile) + choicefile = "pkix.asn"; + + if (!datafile) + datafile = "ocsp.der"; + + /* Encode */ + result = asn1_parser2tree (choicefile, &definitions, errorDescription); + if (result != ASN1_SUCCESS) + { + printf ("error in %d: %s\n", __LINE__, errorDescription); + exit (1); + } + + result = asn1_create_element (definitions, "PKIX1.ResponseData", &node1); + if (result != ASN1_SUCCESS) + { + printf ("error in %d\n", __LINE__); + exit (1); + } + + fp = fopen(datafile, "r"); + if (fp == NULL) + { + printf ("error in %d\n", __LINE__); + exit (1); + } + data_size = fread(data, 1, sizeof(data), fp); + fclose(fp); + + result = asn1_der_decoding (&node1, data, data_size, errorDescription); + if (result != ASN1_SUCCESS) + { + printf ("error in %d: %s\n", __LINE__, errorDescription); + exit (1); + } + + len = sizeof(data2); + result = asn1_der_coding (node1, "", data2, &len, errorDescription); + if (result != ASN1_SUCCESS) + { + printf ("error in %d: %s\n", __LINE__, errorDescription); + exit (1); + } + + if (len != data_size) + { + printf ("length doesn't match (got: %d, should be: %d)\n", len, data_size); + exit (1); + } + + if (memcmp(data, data2, len) != 0) + { + printf ("contents don't match\n"); + exit (1); + } + + asn1_delete_structure (&node1); + asn1_delete_structure (&definitions); + + return 0; +} |