From 853167f231fa10e61d7747b6f028087e76d0eaa6 Mon Sep 17 00:00:00 2001 From: beck <> Date: Sat, 6 May 2017 17:12:59 +0000 Subject: Add ASN1_TIME_set_tm to set an asn1 from a struct tm * ok jsing@ --- src/lib/libcrypto/asn1/a_time_tm.c | 12 +++++++++++- src/lib/libcrypto/asn1/asn1.h | 3 ++- src/lib/libcrypto/man/ASN1_time_parse.3 | 34 ++++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/lib/libcrypto/asn1/a_time_tm.c b/src/lib/libcrypto/asn1/a_time_tm.c index b2f65045b5..f0afc00be4 100644 --- a/src/lib/libcrypto/asn1/a_time_tm.c +++ b/src/lib/libcrypto/asn1/a_time_tm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_time_tm.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */ +/* $OpenBSD: a_time_tm.c,v 1.12 2017/05/06 17:12:59 beck Exp $ */ /* * Copyright (c) 2015 Bob Beck * @@ -303,6 +303,16 @@ ASN1_TIME_set(ASN1_TIME *s, time_t t) return (ASN1_TIME_adj(s, t, 0, 0)); } +ASN1_TIME * +ASN1_TIME_set_tm(ASN1_TIME *s, struct tm *tm) +{ + time_t t; + + if ((t = timegm(tm)) == -1) + return NULL; + return (ASN1_TIME_adj(s, t, 0, 0)); +} + ASN1_TIME * ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec) { diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index e35c865e1f..da16d5c529 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1.h,v 1.42 2016/12/30 16:29:45 jsing Exp $ */ +/* $OpenBSD: asn1.h,v 1.43 2017/05/06 17:12:59 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -939,6 +939,7 @@ extern const ASN1_ITEM ASN1_TIME_it; extern const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it; ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); +ASN1_TIME *ASN1_TIME_set_tm(ASN1_TIME *s, struct tm *tm); ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec); int ASN1_TIME_check(ASN1_TIME *t); diff --git a/src/lib/libcrypto/man/ASN1_time_parse.3 b/src/lib/libcrypto/man/ASN1_time_parse.3 index 77f8b129e2..f14ada5369 100644 --- a/src/lib/libcrypto/man/ASN1_time_parse.3 +++ b/src/lib/libcrypto/man/ASN1_time_parse.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ASN1_time_parse.3,v 1.3 2016/11/05 09:13:56 jmc Exp $ +.\" $OpenBSD: ASN1_time_parse.3,v 1.4 2017/05/06 17:12:59 beck Exp $ .\" .\" Copyright (c) 2016 Bob Beck .\" @@ -14,12 +14,13 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 5 2016 $ +.Dd $Mdocdate: May 6 2017 $ .Dt ASN1_TIME_PARSE 3 .Os .Sh NAME .Nm ASN1_time_parse , -.Nm ASN1_time_tm_cmp +.Nm ASN1_time_tm_cmp, +.Nm ASN1_TIME_set_tm .Nd LibreSSL utilities for ASN.1 time types .Sh SYNOPSIS .In openssl/asn1.h @@ -27,6 +28,8 @@ .Fn ASN1_time_parse "const char *bytes" "size_t len" "struct tm *tm" "int mode" .Ft int .Fn ASN1_time_tm_cmp "struct tm *tm1" "struct tm *tm2" +.Ft ASN1_TIME * +.Fn ASN1_TIME_set_tm "ASN1_TIME *s" "struct tm *tm" .Sh DESCRIPTION The .Fn ASN1_time_parse @@ -62,6 +65,24 @@ function compares two times in .Ar tm1 and .Ar tm2 . +.Pp +The function +.Fn ASN1_TIME_set_tm +sets the +.Vt ASN1_TIME +structure +.Fa s +to the time represented by the +.Vt strict tm +value pointed to by +.Fa tm . +If +.Fa s +is +.Dv NULL , +a new +.Vt ASN1_TIME +structure is allocated and returned. .Sh RETURN VALUES .Fn ASN1_parse_time returns @@ -97,3 +118,10 @@ is greater than is the same as .Ar tm2 . .El +.Pp +.Fn ASN1_TIME_set_tm +returns a pointer to an +.Vt ASN1_TIME +structure or +.Dv NULL +if an error occurred. -- cgit v1.2.3-55-g6feb