From 7b608d0828c6df0b3bcd49224cdf6ccf4ab4af90 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 27 Jul 2017 01:18:50 +0800 Subject: [PATCH] Add test cases and docs for ASN1_STRING_TABLE_* functions Reviewed-by: Richard Levitte Reviewed-by: Andy Polyakov (Merged from https://github.com/openssl/openssl/pull/3998) --- doc/man3/ASN1_STRING_TABLE_add.pod | 65 ++++++++++++++++++++ test/asn1_string_table_test.c | 76 ++++++++++++++++++++++++ test/build.info | 6 +- test/recipes/04-test_asn1_string_table.t | 12 ++++ util/private.num | 1 + 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 doc/man3/ASN1_STRING_TABLE_add.pod create mode 100644 test/asn1_string_table_test.c create mode 100644 test/recipes/04-test_asn1_string_table.t diff --git a/doc/man3/ASN1_STRING_TABLE_add.pod b/doc/man3/ASN1_STRING_TABLE_add.pod new file mode 100644 index 0000000000..e1786bf085 --- /dev/null +++ b/doc/man3/ASN1_STRING_TABLE_add.pod @@ -0,0 +1,65 @@ +=pod + +=head1 NAME + +ASN1_STRING_TABLE, ASN1_STRING_TABLE_add, ASN1_STRING_TABLE_get, +ASN1_STRING_TABLE_cleanup - ASN1_STRING_TABLE manipulation functions + +=head1 SYNOPSIS + + #include + + typedef struct asn1_string_table_st ASN1_STRING_TABLE; + + int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, + unsigned long mask, unsigned long flags); + ASN1_STRING_TABLE * ASN1_STRING_TABLE_get(int nid); + void ASN1_STRING_TABLE_cleanup(void); + +=head1 DESCRIPTION + +=head2 Types + +B is a table which holds string information +(basically minimum size, maximum size, type and etc) for a NID object. + +=head2 Functions + +ASN1_STRING_TABLE_add() adds a new B item into the +local ASN1 string table based on the B along with other parameters. + +If the item is already in the table, fields of B are +updated (depending on the values of those parameters, e.g., B +and B >= 0, B and B != 0). If the B is standard, +a copy of the standard B is created and updated with +other parameters. + +ASN1_STRING_TABLE_get() searches for an B item based +on B. It will search the local table first, then the standard one. + +ASN1_STRING_TABLE_cleanup() frees all B items added +by ASN1_STRING_TABLE_add(). + +=head1 RETURN VALUES + +ASN1_STRING_TABLE_add() returns 1 on success, 0 if an error occurred. + +ASN1_STRING_TABLE_get() returns a valid B structure +or B if nothing is found. + +ASN1_STRING_TABLE_cleanup() does not return a value. + +=head1 SEE ALSO + +L + +=head1 COPYRIGHT + +Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the OpenSSL license (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/test/asn1_string_table_test.c b/test/asn1_string_table_test.c new file mode 100644 index 0000000000..7e542b952e --- /dev/null +++ b/test/asn1_string_table_test.c @@ -0,0 +1,76 @@ +/* + * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* Tests for the ANS1_STRING_TABLE_* functions */ + +#include +#include + +#include +#include "testutil.h" + +static int test_string_tbl() +{ + const ASN1_STRING_TABLE *tmp = NULL; + int nid = 12345678, nid2 = 87654321, rv = 0, ret = 0; + + tmp = ASN1_STRING_TABLE_get(nid); + if (!TEST_ptr_null(tmp)) { + TEST_info("asn1 string table: ASN1_STRING_TABLE_get non-exist nid"); + goto out; + } + + ret = ASN1_STRING_TABLE_add(nid, -1, -1, MBSTRING_ASC, 0); + if (!TEST_true(ret)) { + TEST_info("asn1 string table: add NID(%d) failed", nid); + goto out; + } + + ret = ASN1_STRING_TABLE_add(nid2, -1, -1, MBSTRING_ASC, 0); + if (!TEST_true(ret)) { + TEST_info("asn1 string table: add NID(%d) failed", nid2); + goto out; + } + + tmp = ASN1_STRING_TABLE_get(nid); + if (!TEST_ptr(tmp)) { + TEST_info("asn1 string table: get NID(%d) failed", nid); + goto out; + } + + tmp = ASN1_STRING_TABLE_get(nid2); + if (!TEST_ptr(tmp)) { + TEST_info("asn1 string table: get NID(%d) failed", nid2); + goto out; + } + + ASN1_STRING_TABLE_cleanup(); + + /* check if all newly added NIDs are cleaned up */ + tmp = ASN1_STRING_TABLE_get(nid); + if (!TEST_ptr_null(tmp)) { + TEST_info("asn1 string table: get NID(%d) failed", nid); + goto out; + } + + tmp = ASN1_STRING_TABLE_get(nid2); + if (!TEST_ptr_null(tmp)) { + TEST_info("asn1 string table: get NID(%d) failed", nid2); + goto out; + } + + rv = 1; + out: + return rv; +} + +void register_tests(void) +{ + ADD_TEST(test_string_tbl); +} diff --git a/test/build.info b/test/build.info index a92ff18d09..7b8f654a34 100644 --- a/test/build.info +++ b/test/build.info @@ -41,7 +41,7 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=MAIN dtlsv1listentest ct_test threadstest afalgtest d2i_test \ ssl_test_ctx_test ssl_test x509aux cipherlist_test asynciotest \ bioprinttest sslapitest dtlstest sslcorrupttest bio_enc_test \ - pkey_meth_test uitest cipherbytes_test asn1_encode_test \ + pkey_meth_test uitest cipherbytes_test asn1_encode_test asn1_string_table_test \ x509_time_test x509_dup_cert_test x509_check_cert_pkey_test \ recordlentest drbgtest sslbuffertest \ time_offset_test pemtest ssl_cert_table_internal_test ciphername_test @@ -361,6 +361,10 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=MAIN INCLUDE[asn1_encode_test]=../include DEPEND[asn1_encode_test]=../libcrypto libtestutil.a + SOURCE[asn1_string_table_test]=asn1_string_table_test.c + INCLUDE[asn1_string_table_test]=../include + DEPEND[asn1_string_table_test]=../libcrypto libtestutil.a + SOURCE[time_offset_test]=time_offset_test.c INCLUDE[time_offset_test]=.. ../include DEPEND[time_offset_test]=../libcrypto libtestutil.a diff --git a/test/recipes/04-test_asn1_string_table.t b/test/recipes/04-test_asn1_string_table.t new file mode 100644 index 0000000000..041f372157 --- /dev/null +++ b/test/recipes/04-test_asn1_string_table.t @@ -0,0 +1,12 @@ +#! /usr/bin/env perl +# Copyright 2017 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + + +use OpenSSL::Test::Simple; + +simple_test("test_asn1_string_table", "asn1_string_table_test"); diff --git a/util/private.num b/util/private.num index 203b5316b0..ff45e56885 100644 --- a/util/private.num +++ b/util/private.num @@ -8,6 +8,7 @@ OPENSSL_MALLOC_FAILURES environment OPENSSL_instrument_bus assembler OPENSSL_instrument_bus2 assembler # +ASN1_STRING_TABLE datatype BIO_ADDR datatype BIO_ADDRINFO datatype BIO_callback_fn datatype -- 2.34.1