summaryrefslogtreecommitdiffstats
path: root/crypto/asn1
diff options
context:
space:
mode:
authorArmin Fuerst <armin@fuerst.priv.at>2022-02-04 20:35:54 +0100
committerTomas Mraz <tomas@openssl.org>2022-02-14 10:18:46 +0100
commit065121ff198a84106023013420dedd57ac4ff53a (patch)
treeff7da729a33d0380267dbc080a528b3d0f1cf6a9 /crypto/asn1
parentc920020f0bb13f0d2bf0fcad5c7ee63458b633b4 (diff)
Add tests for do_updatedb
Fixes #13944 Moved "opt_printf_stderr" out of apps.c to avoid duplicate definition in tests. Added function "asn1_string_to_time_t" including tests. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17645)
Diffstat (limited to 'crypto/asn1')
-rw-r--r--crypto/asn1/a_time.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c
index 9b3074e47e..e9df23af92 100644
--- a/crypto/asn1/a_time.c
+++ b/crypto/asn1/a_time.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -589,3 +589,41 @@ int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b)
return -1;
return 0;
}
+
+/*
+ * tweak for Windows
+ */
+#ifdef WIN32
+# define timezone _timezone
+#endif
+
+time_t asn1_string_to_time_t(const char *asn1_string)
+{
+ ASN1_TIME *timestamp_asn1 = NULL;
+ struct tm *timestamp_tm = NULL;
+ time_t timestamp_local;
+ time_t timestamp_utc;
+
+ timestamp_asn1 = ASN1_TIME_new();
+ if (!ASN1_TIME_set_string(timestamp_asn1, asn1_string))
+ {
+ ASN1_TIME_free(timestamp_asn1);
+ return -1;
+ }
+
+ timestamp_tm = OPENSSL_malloc(sizeof(*timestamp_tm));
+
+ if (!(ASN1_TIME_to_tm(timestamp_asn1, timestamp_tm))) {
+ OPENSSL_free(timestamp_tm);
+ ASN1_TIME_free(timestamp_asn1);
+ return -1;
+ }
+
+ timestamp_local = mktime(timestamp_tm);
+ OPENSSL_free(timestamp_tm);
+
+ timestamp_utc = timestamp_local - timezone;
+
+ ASN1_TIME_free(timestamp_asn1);
+ return timestamp_utc;
+}