summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-11-23 21:00:50 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-11-23 21:00:50 +0100
commit1d02266a174c939e9ca1460641c8eaa9dc2a7843 (patch)
treecebb21db31dece4ebca130c04d6bfe8344b82ee0 /tests
parentd23e8f3918d401fbaa25a1342b5db368f9f3adef (diff)
downloadlibtasn1-1d02266a174c939e9ca1460641c8eaa9dc2a7843.tar.gz
libtasn1-1d02266a174c939e9ca1460641c8eaa9dc2a7843.tar.bz2
libtasn1-1d02266a174c939e9ca1460641c8eaa9dc2a7843.zip
simplified and renamed asn1_encode_string_der() and asn1_decode_string_der()
Diffstat (limited to 'tests')
-rw-r--r--tests/Test_strings.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/tests/Test_strings.c b/tests/Test_strings.c
index c2b9da1..b43620f 100644
--- a/tests/Test_strings.c
+++ b/tests/Test_strings.c
@@ -37,7 +37,7 @@ struct tv
static const struct tv tv[] = {
{ASN1_ETYPE_IA5_STRING, 20, "\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72",
- 22, "\x16\x14\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72"},
+ 22, "\x16\x14\x63\x73\x63\x61\x40\x70\x61\x73\x73\x70\x6f\x72\x74\x2e\x67\x6f\x76\x2e\x67\x72"},
{ASN1_ETYPE_PRINTABLE_STRING, 5, "\x4e\x69\x6b\x6f\x73",
7, "\x13\x05\x4e\x69\x6b\x6f\x73"},
{ASN1_ETYPE_UTF8_STRING, 12, "Αττική",
@@ -52,8 +52,9 @@ int
main (int argc, char *argv[])
{
int ret;
- unsigned char* der;
- unsigned int der_len;
+ unsigned char tl[ASN1_MAX_TL_SIZE];
+ unsigned int tl_len, der_len, str_len;
+ const unsigned char* str;
unsigned int i;
/* Dummy test */
@@ -61,35 +62,35 @@ main (int argc, char *argv[])
for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
{
/* Encode */
- ret = asn1_encode_string_der(tv[i].etype, tv[i].str, tv[i].str_len,
- &der, &der_len);
+ tl_len = sizeof(tl);
+ ret = asn1_encode_simple_der(tv[i].etype, tv[i].str, tv[i].str_len,
+ tl, &tl_len);
if (ret != ASN1_SUCCESS)
{
fprintf(stderr, "Encoding error in %u: %s\n", i, asn1_strerror(ret));
return 1;
}
+ der_len = tl_len+tv[i].str_len;
- if (der_len != tv[i].der_len || memcmp(der, tv[i].der, der_len) != 0)
+ if (der_len != tv[i].der_len || memcmp(tl, tv[i].der, tl_len) != 0)
{
fprintf(stderr, "DER encoding differs in %u! (size: %u, expected: %u)\n", i, der_len, tv[i].der_len);
return 1;
}
- free(der);
/* decoding */
- ret = asn1_decode_string_der(tv[i].etype, tv[i].der, tv[i].der_len, &der, &der_len);
+ ret = asn1_decode_simple_der(tv[i].etype, tv[i].der, tv[i].der_len, &str, &str_len);
if (ret != ASN1_SUCCESS)
{
fprintf(stderr, "Decoding error in %u: %s\n", i, asn1_strerror(ret));
return 1;
}
- if (der_len != tv[i].str_len || memcmp(der, tv[i].str, der_len) != 0)
+ if (str_len != tv[i].str_len || memcmp(str, tv[i].str, str_len) != 0)
{
fprintf(stderr, "DER decoded data differ in %u! (size: %u, expected: %u)\n", i, der_len, tv[i].str_len);
return 1;
}
- free(der);
}