Test that built-in ASN1_STRING_TABLEs are sorted.

There's a test in the file under ifdef, but that is not wired up into
the build.

Change-Id: Iec09277c7ce948c33303d12c325207de2188d908
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/49766
Reviewed-by: Adam Langley <agl@google.com>
grpc-202302
David Benjamin 3 years ago committed by Adam Langley
parent fa6ced9512
commit a50f24c854
  1. 37
      crypto/asn1/a_strnid.c
  2. 10
      crypto/asn1/asn1_test.cc
  3. 5
      crypto/asn1/internal.h

@ -64,6 +64,10 @@
#include <openssl/obj.h>
#include <openssl/stack.h>
#include "../internal.h"
#include "internal.h"
DEFINE_STACK_OF(ASN1_STRING_TABLE)
static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
@ -244,33 +248,8 @@ static void st_free(ASN1_STRING_TABLE *tbl)
OPENSSL_free(tbl);
}
#ifdef STRING_TABLE_TEST
int main(void)
{
ASN1_STRING_TABLE *tmp;
int i, last_nid = -1;
for (tmp = tbl_standard, i = 0;
i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) {
if (tmp->nid < last_nid) {
last_nid = 0;
break;
}
last_nid = tmp->nid;
}
if (last_nid != 0) {
printf("Table order OK\n");
exit(0);
}
for (tmp = tbl_standard, i = 0;
i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++)
printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
OBJ_nid2ln(tmp->nid));
return 0;
void asn1_get_string_table_for_testing(const ASN1_STRING_TABLE **out_ptr,
size_t *out_len) {
*out_ptr = tbl_standard;
*out_len = OPENSSL_ARRAY_SIZE(tbl_standard);
}
#endif

@ -30,6 +30,7 @@
#include <openssl/x509v3.h>
#include "../test/test_util.h"
#include "internal.h"
// kTag128 is an ASN.1 structure with a universal tag with number 128.
@ -1119,6 +1120,15 @@ TEST(ASN1Test, InvalidMSTRING) {
EXPECT_EQ(-1, i2d_DIRECTORYSTRING(obj.get(), nullptr));
}
TEST(ASN1Test, StringTableSorted) {
const ASN1_STRING_TABLE *table;
size_t table_len;
asn1_get_string_table_for_testing(&table, &table_len);
for (size_t i = 1; i < table_len; i++) {
EXPECT_LT(table[i-1].nid, table[i].nid);
}
}
// The ASN.1 macros do not work on Windows shared library builds, where usage of
// |OPENSSL_EXPORT| is a bit stricter.
#if !defined(OPENSSL_WINDOWS) || !defined(BORINGSSL_SHARED_LIBRARY)

@ -175,6 +175,11 @@ const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
* ASN.1 PrintableString, and zero otherwise. */
int asn1_is_printable(uint32_t value);
/* asn1_get_string_table_for_testing sets |*out_ptr| and |*out_len| to the table
* of built-in |ASN1_STRING_TABLE| values. It is exported for testing. */
OPENSSL_EXPORT void asn1_get_string_table_for_testing(
const ASN1_STRING_TABLE **out_ptr, size_t *out_len);
#if defined(__cplusplus)
} /* extern C */

Loading…
Cancel
Save