summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2022-03-05 14:16:13 +0000
committerjsing <>2022-03-05 14:16:13 +0000
commit1e42bd9e39a64f2c9f61444f3f32e30f28b2345a (patch)
tree9213c4cbc530891c3fdcdbb38f86ab8ce2241a09 /src
parentf1c77c6f14665db63d85ca49365a3258bb34354a (diff)
downloadopenbsd-1e42bd9e39a64f2c9f61444f3f32e30f28b2345a.tar.gz
openbsd-1e42bd9e39a64f2c9f61444f3f32e30f28b2345a.tar.bz2
openbsd-1e42bd9e39a64f2c9f61444f3f32e30f28b2345a.zip
Add test coverage for i2a_ASN1_OBJECT()
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/asn1/asn1object.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1object.c b/src/regress/lib/libcrypto/asn1/asn1object.c
index 0051f2c6e7..2c43f0edc4 100644
--- a/src/regress/lib/libcrypto/asn1/asn1object.c
+++ b/src/regress/lib/libcrypto/asn1/asn1object.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1object.c,v 1.2 2022/03/02 17:39:56 jsing Exp $ */ 1/* $OpenBSD: asn1object.c,v 1.3 2022/03/05 14:16:13 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2017, 2021, 2022 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2017, 2021, 2022 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -397,10 +397,14 @@ asn1_object_bad_content_test(void)
397static int 397static int
398asn1_object_txt_test(void) 398asn1_object_txt_test(void)
399{ 399{
400 const char *obj_txt = "organizationName";
400 ASN1_OBJECT *aobj = NULL; 401 ASN1_OBJECT *aobj = NULL;
401 uint8_t small_buf[2]; 402 uint8_t small_buf[2];
402 const uint8_t *p; 403 const uint8_t *p;
403 int err, len, ret; 404 int err, len, ret;
405 BIO *bio = NULL;
406 char *data;
407 long data_len;
404 int failed = 1; 408 int failed = 1;
405 409
406 ERR_clear_error(); 410 ERR_clear_error();
@@ -426,9 +430,40 @@ asn1_object_txt_test(void)
426 goto failed; 430 goto failed;
427 } 431 }
428 ret = i2t_ASN1_OBJECT(small_buf, sizeof(small_buf), aobj); 432 ret = i2t_ASN1_OBJECT(small_buf, sizeof(small_buf), aobj);
429 if (ret != 16) { 433 if (ret < 0 || (unsigned long)ret != strlen(obj_txt)) {
430 fprintf(stderr, "FAIL: i2t_ASN1_OBJECT() with small buffer " 434 fprintf(stderr, "FAIL: i2t_ASN1_OBJECT() with small buffer "
431 "returned %d, want %d\n", ret, 16); 435 "returned %d, want %lu\n", ret, strlen(obj_txt));
436 goto failed;
437 }
438
439 if ((bio = BIO_new(BIO_s_mem())) == NULL) {
440 fprintf(stderr, "FAIL: BIO_new() returned NULL\n");
441 goto failed;
442 }
443 ret = i2a_ASN1_OBJECT(bio, NULL);
444 if (ret != 4) {
445 fprintf(stderr, "FAIL: i2a_ASN1_OBJECT(_, NULL) returned %d, "
446 "want 4\n", ret);
447 goto failed;
448 }
449 data_len = BIO_get_mem_data(bio, &data);
450 if (ret != data_len || memcmp("NULL", data, data_len) != 0) {
451 fprintf(stderr, "FAIL: i2a_ASN1_OBJECT(_, NULL) did not return "
452 "'NULL'\n");
453 goto failed;
454 }
455
456 BIO_reset(bio);
457 ret = i2a_ASN1_OBJECT(bio, aobj);
458 if (ret < 0 || (unsigned long)ret != strlen(obj_txt)) {
459 fprintf(stderr, "FAIL: i2a_ASN1_OBJECT() returned %d, "
460 "want %lu\n", ret, strlen(obj_txt));
461 goto failed;
462 }
463 data_len = BIO_get_mem_data(bio, &data);
464 if (ret != data_len || memcmp(obj_txt, data, data_len) != 0) {
465 fprintf(stderr, "FAIL: i2a_ASN1_OBJECT() did not return "
466 "'%s'\n", obj_txt);
432 goto failed; 467 goto failed;
433 } 468 }
434 469
@@ -436,6 +471,7 @@ asn1_object_txt_test(void)
436 471
437 failed: 472 failed:
438 ASN1_OBJECT_free(aobj); 473 ASN1_OBJECT_free(aobj);
474 BIO_free(bio);
439 475
440 return failed; 476 return failed;
441} 477}