summaryrefslogtreecommitdiff
path: root/tests/object-id-decoding.c
diff options
context:
space:
mode:
authorDariusz Michaluk <d.michaluk@samsung.com>2024-02-13 15:44:51 +0100
committerDariusz Michaluk <d.michaluk@samsung.com>2024-02-14 10:46:44 +0100
commitc28e9eeaa4dccef63b3b237ebe8a8b5abb23e335 (patch)
tree504a1953b56446487f4759d3a5f348bbeb925461 /tests/object-id-decoding.c
parent1778d37a3eec1209d7c9c064318f3ff8c5132490 (diff)
parent031996ef501f8c3d0532f7df1c38cf2e540a4f11 (diff)
downloadlibtasn1-accepted/tizen_unified.tar.gz
libtasn1-accepted/tizen_unified.tar.bz2
libtasn1-accepted/tizen_unified.zip
Change-Id: I893fd2c90c487d6e13b0b10e25b2cafc408da180
Diffstat (limited to 'tests/object-id-decoding.c')
-rw-r--r--tests/object-id-decoding.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/tests/object-id-decoding.c b/tests/object-id-decoding.c
index e3e9669..06a6c52 100644
--- a/tests/object-id-decoding.c
+++ b/tests/object-id-decoding.c
@@ -27,18 +27,46 @@
struct tv
{
int der_len;
- const unsigned char *der_str;
+ const unsigned char *der;
const char *oid;
int expected_error;
};
static const struct tv tv[] = {
+ {.der_len = 5,
+ .der = (void *) "\x06\x03\x80\x37\x03",
+ .oid = "2.999.3",
+ .expected_error = ASN1_DER_ERROR /* leading 0x80 */
+ },
{.der_len = 12,
- .der_str = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01",
+ .der = (void *) "\x06\x0a\x2b\x06\x01\x80\x01\x92\x08\x09\x05\x01",
+ .oid = "1.3.6.1.4.1.2312.9.5.1",
+ .expected_error = ASN1_DER_ERROR /* leading 0x80 */
+ },
+ {.der_len = 6,
+ .der = (void *) "\x06\x04\x01\x02\x03\x04",
+ .oid = "0.1.2.3.4",
+ .expected_error = ASN1_SUCCESS},
+ {.der_len = 5,
+ .der = (void *) "\x06\x03\x51\x02\x03",
+ .oid = "2.1.2.3",
+ .expected_error = ASN1_SUCCESS},
+ {.der_len = 5,
+ .der = (void *) "\x06\x03\x88\x37\x03",
+ .oid = "2.999.3",
+ .expected_error = ASN1_SUCCESS},
+ {.der_len = 12,
+ .der = (void *) "\x06\x0a\x2b\x06\x01\x04\x01\x92\x08\x09\x05\x01",
.oid = "1.3.6.1.4.1.2312.9.5.1",
.expected_error = ASN1_SUCCESS},
{.der_len = 19,
- .der_str =
+ .der =
+ (void *)
+ "\x06\x11\xfa\x80\x00\x00\x00\x0e\x01\x0e\xfa\x80\x00\x00\x00\x0e\x63\x6f\x6d",
+ .oid = "2.1998768.0.0.14.1.14.1998848.0.0.14.99.111.109",
+ .expected_error = ASN1_SUCCESS},
+ {.der_len = 19,
+ .der =
(void *)
"\x06\x11\x2b\x06\x01\x04\x01\x92\x08\x09\x02\xaa\xda\xbe\xbe\xfa\x72\x01\x07",
.oid = "1.3.6.1.4.1.2312.9.2.1467399257458.1.7",
@@ -56,22 +84,26 @@ main (int argc, char *argv[])
{
/* decode */
ret =
- asn1_get_object_id_der (tv[i].der_str+1,
- tv[i].der_len-1, &ret_len, str,
+ asn1_get_object_id_der (tv[i].der + 1,
+ tv[i].der_len - 1, &ret_len, str,
sizeof (str));
if (ret != tv[i].expected_error)
{
fprintf (stderr,
- "%d: asn1_get_object_id_der iter %lu: got %d expected %d\n",
- __LINE__, (unsigned long) i, ret, tv[i].expected_error);
+ "%d: asn1_get_object_id_der iter %lu: got '%s' expected %d\n",
+ __LINE__, (unsigned long) i, asn1_strerror (ret),
+ tv[i].expected_error);
return 1;
}
- if (ret_len != tv[i].der_len-1)
+ if (tv[i].expected_error != ASN1_SUCCESS)
+ continue;
+
+ if (ret_len != tv[i].der_len - 1)
{
fprintf (stderr,
"%d: iter %lu: error in DER, length returned is %d, had %d\n",
- __LINE__, (unsigned long)i, ret_len, tv[i].der_len-1);
+ __LINE__, (unsigned long) i, ret_len, tv[i].der_len - 1);
return 1;
}