[openssl-commits] [openssl] master update

Andy Polyakov appro at openssl.org
Wed Jul 26 18:08:40 UTC 2017


The branch master has been updated
       via  7b608d0828c6df0b3bcd49224cdf6ccf4ab4af90 (commit)
      from  e4b16013e9b3d19241d3ba0bb0875f0d70d93509 (commit)


- Log -----------------------------------------------------------------
commit 7b608d0828c6df0b3bcd49224cdf6ccf4ab4af90
Author: Paul Yang <yang.yang at baishancloud.com>
Date:   Thu Jul 27 01:18:50 2017 +0800

    Add test cases and docs for ASN1_STRING_TABLE_* functions
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    Reviewed-by: Andy Polyakov <appro at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3998)

-----------------------------------------------------------------------

Summary of changes:
 doc/man3/ASN1_STRING_TABLE_add.pod                 | 65 ++++++++++++++++++
 test/asn1_string_table_test.c                      | 76 ++++++++++++++++++++++
 test/build.info                                    |  6 +-
 ...3-test_exdata.t => 04-test_asn1_string_table.t} |  2 +-
 util/private.num                                   |  1 +
 5 files changed, 148 insertions(+), 2 deletions(-)
 create mode 100644 doc/man3/ASN1_STRING_TABLE_add.pod
 create mode 100644 test/asn1_string_table_test.c
 copy test/recipes/{03-test_exdata.t => 04-test_asn1_string_table.t} (84%)

diff --git a/doc/man3/ASN1_STRING_TABLE_add.pod b/doc/man3/ASN1_STRING_TABLE_add.pod
new file mode 100644
index 0000000..e1786bf
--- /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 <openssl/asn1.h>
+
+ 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<ASN1_STRING_TABLE> 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<ASN1_STRING_TABLE> item into the
+local ASN1 string table based on the B<nid> along with other parameters.
+
+If the item is already in the table, fields of B<ASN1_STRING_TABLE> are
+updated (depending on the values of those parameters, e.g., B<minsize>
+and B<maxsize> >= 0, B<mask> and B<flags> != 0). If the B<nid> is standard,
+a copy of the standard B<ASN1_STRING_TABLE> is created and updated with
+other parameters.
+
+ASN1_STRING_TABLE_get() searches for an B<ASN1_STRING_TABLE> item based
+on B<nid>. It will search the local table first, then the standard one.
+
+ASN1_STRING_TABLE_cleanup() frees all B<ASN1_STRING_TABLE> 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<ASN1_STRING_TABLE> structure
+or B<NULL> if nothing is found.
+
+ASN1_STRING_TABLE_cleanup() does not return a value.
+
+=head1 SEE ALSO
+
+L<ERR_get_error(3)>
+
+=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<https://www.openssl.org/source/license.html>.
+
+=cut
diff --git a/test/asn1_string_table_test.c b/test/asn1_string_table_test.c
new file mode 100644
index 0000000..7e542b9
--- /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 <stdio.h>
+#include <string.h>
+
+#include <openssl/asn1.h>
+#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 a92ff18..7b8f654 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/03-test_exdata.t b/test/recipes/04-test_asn1_string_table.t
similarity index 84%
copy from test/recipes/03-test_exdata.t
copy to test/recipes/04-test_asn1_string_table.t
index da66f95..041f372 100644
--- a/test/recipes/03-test_exdata.t
+++ b/test/recipes/04-test_asn1_string_table.t
@@ -9,4 +9,4 @@
 
 use OpenSSL::Test::Simple;
 
-simple_test("test_exdata", "exdatatest");
+simple_test("test_asn1_string_table", "asn1_string_table_test");
diff --git a/util/private.num b/util/private.num
index 203b531..ff45e56 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


More information about the openssl-commits mailing list