summaryrefslogtreecommitdiff
path: root/src/regress/lib/libssl
diff options
context:
space:
mode:
authordoug <>2015-06-16 06:37:58 +0000
committerdoug <>2015-06-16 06:37:58 +0000
commit924d478ace6d3fb8033502da649ef6094b7ee75a (patch)
treeca21a350b439c40324eb3a0fa186f4a28038a4fa /src/regress/lib/libssl
parentd44d9785ffbec94f6960b1a4f5dfd26c3faad092 (diff)
downloadopenbsd-924d478ace6d3fb8033502da649ef6094b7ee75a.tar.gz
openbsd-924d478ace6d3fb8033502da649ef6094b7ee75a.tar.bz2
openbsd-924d478ace6d3fb8033502da649ef6094b7ee75a.zip
Be more strict about BER and DER terminology.
bs_ber.c does not convert BER to DER. It's a hack to convert a DER-like encoding with one violation (indefinite form) to strict DER. Rename the functions to reflect this. ok miod@ jsing@
Diffstat (limited to 'src/regress/lib/libssl')
-rw-r--r--src/regress/lib/libssl/bytestring/bytestringtest.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/regress/lib/libssl/bytestring/bytestringtest.c b/src/regress/lib/libssl/bytestring/bytestringtest.c
index 7ae9397a35..05ca27e8b5 100644
--- a/src/regress/lib/libssl/bytestring/bytestringtest.c
+++ b/src/regress/lib/libssl/bytestring/bytestringtest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bytestringtest.c,v 1.4 2015/04/25 15:28:47 doug Exp $ */ 1/* $OpenBSD: bytestringtest.c,v 1.5 2015/06/16 06:37:58 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -484,23 +484,25 @@ err:
484} 484}
485 485
486static int 486static int
487do_ber_convert(const char *name, const uint8_t *der_expected, size_t der_len, 487do_indefinite_convert(const char *name, const uint8_t *definite_expected,
488 const uint8_t *ber, size_t ber_len) 488 size_t definite_len, const uint8_t *indefinite, size_t indefinite_len)
489{ 489{
490 CBS in; 490 CBS in;
491 uint8_t *out = NULL; 491 uint8_t *out = NULL;
492 size_t out_len; 492 size_t out_len;
493 int ret = 0; 493 int ret = 0;
494 494
495 CBS_init(&in, ber, ber_len); 495 CBS_init(&in, indefinite, indefinite_len);
496 if (!CBS_asn1_ber_to_der(&in, &out, &out_len)) { 496 if (!CBS_asn1_indefinite_to_definite(&in, &out, &out_len)) {
497 fprintf(stderr, "%s: CBS_asn1_ber_to_der failed.\n", name); 497 fprintf(stderr, "%s: CBS_asn1_indefinite_to_definite failed.\n",
498 name);
498 goto end; 499 goto end;
499 } 500 }
500 501
501 if (out == NULL) { 502 if (out == NULL) {
502 if (ber_len != der_len || 503 if (indefinite_len != definite_len ||
503 memcmp(der_expected, ber, ber_len) != 0) { 504 memcmp(definite_expected, indefinite, indefinite_len)
505 != 0) {
504 fprintf(stderr, "%s: incorrect unconverted result.\n", 506 fprintf(stderr, "%s: incorrect unconverted result.\n",
505 name); 507 name);
506 return 0; 508 return 0;
@@ -509,7 +511,8 @@ do_ber_convert(const char *name, const uint8_t *der_expected, size_t der_len,
509 return 1; 511 return 1;
510 } 512 }
511 513
512 if (out_len != der_len || memcmp(out, der_expected, der_len) != 0) { 514 if (out_len != definite_len || memcmp(out, definite_expected,
515 definite_len) != 0) {
513 fprintf(stderr, "%s: incorrect converted result.\n", name); 516 fprintf(stderr, "%s: incorrect converted result.\n", name);
514 goto end; 517 goto end;
515 } 518 }
@@ -522,7 +525,7 @@ end:
522} 525}
523 526
524static int 527static int
525test_ber_convert(void) 528test_indefinite_convert(void)
526{ 529{
527 static const uint8_t kSimpleBER[] = {0x01, 0x01, 0x00}; 530 static const uint8_t kSimpleBER[] = {0x01, 0x01, 0x00};
528 531
@@ -566,14 +569,14 @@ test_ber_convert(void)
566 0x6e, 0x10, 0x9b, 0xb8, 0x02, 0x02, 0x07, 0xd0, 569 0x6e, 0x10, 0x9b, 0xb8, 0x02, 0x02, 0x07, 0xd0,
567 }; 570 };
568 571
569 return do_ber_convert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER), 572 return do_indefinite_convert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER),
570 kSimpleBER, sizeof(kSimpleBER)) && 573 kSimpleBER, sizeof(kSimpleBER)) &&
571 do_ber_convert("kIndefBER", kIndefDER, sizeof(kIndefDER), kIndefBER, 574 do_indefinite_convert("kIndefBER", kIndefDER, sizeof(kIndefDER), kIndefBER,
572 sizeof(kIndefBER)) && 575 sizeof(kIndefBER)) &&
573 do_ber_convert("kOctetStringBER", kOctetStringDER, 576 do_indefinite_convert("kOctetStringBER", kOctetStringDER,
574 sizeof(kOctetStringDER), kOctetStringBER, 577 sizeof(kOctetStringDER), kOctetStringBER,
575 sizeof(kOctetStringBER)) && 578 sizeof(kOctetStringBER)) &&
576 do_ber_convert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER, 579 do_indefinite_convert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER,
577 sizeof(kNSSBER)); 580 sizeof(kNSSBER));
578} 581}
579 582
@@ -682,7 +685,7 @@ main(void)
682 !test_cbb_misuse() || 685 !test_cbb_misuse() ||
683 !test_cbb_prefixed() || 686 !test_cbb_prefixed() ||
684 !test_cbb_asn1() || 687 !test_cbb_asn1() ||
685 !test_ber_convert() || 688 !test_indefinite_convert() ||
686 !test_asn1_uint64() || 689 !test_asn1_uint64() ||
687 !test_get_optional_asn1_bool()) 690 !test_get_optional_asn1_bool())
688 return 1; 691 return 1;