summaryrefslogtreecommitdiff
path: root/test/asn1_time_test.c
diff options
context:
space:
mode:
authorPaul Yang <kaishen.yy@antfin.com>2020-01-13 14:26:11 +0800
committerPaul Yang <kaishen.yy@antfin.com>2020-01-17 11:30:33 +0800
commitfe4309b0de64502398116f648cc7f2068e1a1537 (patch)
treea4bc6f6fe4b87f1984ae05e94fe1ff2e5362a0c6 /test/asn1_time_test.c
parent83c51006759437b8643264c5fb748030fd6aaef5 (diff)
downloadopenssl-new-fe4309b0de64502398116f648cc7f2068e1a1537.tar.gz
Add duplication APIs to ASN1_TIME and related types
Fixes #10600. Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/10823)
Diffstat (limited to 'test/asn1_time_test.c')
-rw-r--r--test/asn1_time_test.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/asn1_time_test.c b/test/asn1_time_test.c
index a619b37302..b1a107da61 100644
--- a/test/asn1_time_test.c
+++ b/test/asn1_time_test.c
@@ -320,6 +320,65 @@ static int test_table_compare(int idx)
return TEST_int_eq(ASN1_TIME_compare(&td->t1, &td->t2), td->result);
}
+static int test_time_dup(void)
+{
+ int ret = 0;
+ ASN1_TIME *asn1_time = NULL;
+ ASN1_TIME *asn1_time_dup = NULL;
+ ASN1_TIME *asn1_gentime = NULL;
+
+ asn1_time = ASN1_TIME_adj(NULL, time(NULL), 0, 0);
+ if (asn1_time == NULL) {
+ TEST_info("Internal error.");
+ goto err;
+ }
+
+ asn1_gentime = ASN1_TIME_to_generalizedtime(asn1_time, NULL);
+ if (asn1_gentime == NULL) {
+ TEST_info("Internal error.");
+ goto err;
+ }
+
+ asn1_time_dup = ASN1_TIME_dup(asn1_time);
+ if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
+ TEST_info("ASN1_TIME_dup() failed.");
+ goto err;
+ }
+ if (!TEST_int_eq(ASN1_TIME_compare(asn1_time, asn1_time_dup), 0)) {
+ TEST_info("ASN1_TIME_dup() duplicated non-identical value.");
+ goto err;
+ }
+ ASN1_STRING_free(asn1_time_dup);
+
+ asn1_time_dup = ASN1_UTCTIME_dup(asn1_time);
+ if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
+ TEST_info("ASN1_UTCTIME_dup() failed.");
+ goto err;
+ }
+ if (!TEST_int_eq(ASN1_TIME_compare(asn1_time, asn1_time_dup), 0)) {
+ TEST_info("ASN1_UTCTIME_dup() duplicated non-identical UTCTIME value.");
+ goto err;
+ }
+ ASN1_STRING_free(asn1_time_dup);
+
+ asn1_time_dup = ASN1_GENERALIZEDTIME_dup(asn1_gentime);
+ if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
+ TEST_info("ASN1_GENERALIZEDTIME_dup() failed.");
+ goto err;
+ }
+ if (!TEST_int_eq(ASN1_TIME_compare(asn1_gentime, asn1_time_dup), 0)) {
+ TEST_info("ASN1_GENERALIZEDTIME_dup() dup'ed non-identical value.");
+ goto err;
+ }
+
+ ret = 1;
+ err:
+ ASN1_STRING_free(asn1_time);
+ ASN1_STRING_free(asn1_gentime);
+ ASN1_STRING_free(asn1_time_dup);
+ return ret;
+}
+
int setup_tests(void)
{
/*
@@ -354,5 +413,6 @@ int setup_tests(void)
#endif
}
ADD_ALL_TESTS(test_table_compare, OSSL_NELEM(tbl_compare_testdata));
+ ADD_TEST(test_time_dup);
return 1;
}