diff options
author | beck <> | 2017-05-06 17:12:59 +0000 |
---|---|---|
committer | beck <> | 2017-05-06 17:12:59 +0000 |
commit | 853167f231fa10e61d7747b6f028087e76d0eaa6 (patch) | |
tree | dc9c35b12d4ec6d0389f08be9ff6d7183a4f80d4 | |
parent | d9dc0bed247af8759a2ecc0116b8f9539291435e (diff) | |
download | openbsd-853167f231fa10e61d7747b6f028087e76d0eaa6.tar.gz openbsd-853167f231fa10e61d7747b6f028087e76d0eaa6.tar.bz2 openbsd-853167f231fa10e61d7747b6f028087e76d0eaa6.zip |
Add ASN1_TIME_set_tm to set an asn1 from a struct tm *
ok jsing@
-rw-r--r-- | src/lib/libcrypto/asn1/a_time_tm.c | 12 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1.h | 3 | ||||
-rw-r--r-- | 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 @@ | |||
1 | /* $OpenBSD: a_time_tm.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */ | 1 | /* $OpenBSD: a_time_tm.c,v 1.12 2017/05/06 17:12:59 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2015 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2015 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -304,6 +304,16 @@ ASN1_TIME_set(ASN1_TIME *s, time_t t) | |||
304 | } | 304 | } |
305 | 305 | ||
306 | ASN1_TIME * | 306 | ASN1_TIME * |
307 | ASN1_TIME_set_tm(ASN1_TIME *s, struct tm *tm) | ||
308 | { | ||
309 | time_t t; | ||
310 | |||
311 | if ((t = timegm(tm)) == -1) | ||
312 | return NULL; | ||
313 | return (ASN1_TIME_adj(s, t, 0, 0)); | ||
314 | } | ||
315 | |||
316 | ASN1_TIME * | ||
307 | ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec) | 317 | ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec) |
308 | { | 318 | { |
309 | return (ASN1_TIME_adj_internal(s, t, offset_day, offset_sec, RFC5280)); | 319 | return (ASN1_TIME_adj_internal(s, t, offset_day, offset_sec, RFC5280)); |
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 @@ | |||
1 | /* $OpenBSD: asn1.h,v 1.42 2016/12/30 16:29:45 jsing Exp $ */ | 1 | /* $OpenBSD: asn1.h,v 1.43 2017/05/06 17:12:59 beck Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -939,6 +939,7 @@ extern const ASN1_ITEM ASN1_TIME_it; | |||
939 | extern const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it; | 939 | extern const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it; |
940 | 940 | ||
941 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); | 941 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); |
942 | ASN1_TIME *ASN1_TIME_set_tm(ASN1_TIME *s, struct tm *tm); | ||
942 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, | 943 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, |
943 | long offset_sec); | 944 | long offset_sec); |
944 | int ASN1_TIME_check(ASN1_TIME *t); | 945 | 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 @@ | |||
1 | .\" $OpenBSD: ASN1_time_parse.3,v 1.3 2016/11/05 09:13:56 jmc Exp $ | 1 | .\" $OpenBSD: ASN1_time_parse.3,v 1.4 2017/05/06 17:12:59 beck Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2016 Bob Beck <beck@openbsd.org> | 3 | .\" Copyright (c) 2016 Bob Beck <beck@openbsd.org> |
4 | .\" | 4 | .\" |
@@ -14,12 +14,13 @@ | |||
14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | .\" | 16 | .\" |
17 | .Dd $Mdocdate: November 5 2016 $ | 17 | .Dd $Mdocdate: May 6 2017 $ |
18 | .Dt ASN1_TIME_PARSE 3 | 18 | .Dt ASN1_TIME_PARSE 3 |
19 | .Os | 19 | .Os |
20 | .Sh NAME | 20 | .Sh NAME |
21 | .Nm ASN1_time_parse , | 21 | .Nm ASN1_time_parse , |
22 | .Nm ASN1_time_tm_cmp | 22 | .Nm ASN1_time_tm_cmp, |
23 | .Nm ASN1_TIME_set_tm | ||
23 | .Nd LibreSSL utilities for ASN.1 time types | 24 | .Nd LibreSSL utilities for ASN.1 time types |
24 | .Sh SYNOPSIS | 25 | .Sh SYNOPSIS |
25 | .In openssl/asn1.h | 26 | .In openssl/asn1.h |
@@ -27,6 +28,8 @@ | |||
27 | .Fn ASN1_time_parse "const char *bytes" "size_t len" "struct tm *tm" "int mode" | 28 | .Fn ASN1_time_parse "const char *bytes" "size_t len" "struct tm *tm" "int mode" |
28 | .Ft int | 29 | .Ft int |
29 | .Fn ASN1_time_tm_cmp "struct tm *tm1" "struct tm *tm2" | 30 | .Fn ASN1_time_tm_cmp "struct tm *tm1" "struct tm *tm2" |
31 | .Ft ASN1_TIME * | ||
32 | .Fn ASN1_TIME_set_tm "ASN1_TIME *s" "struct tm *tm" | ||
30 | .Sh DESCRIPTION | 33 | .Sh DESCRIPTION |
31 | The | 34 | The |
32 | .Fn ASN1_time_parse | 35 | .Fn ASN1_time_parse |
@@ -62,6 +65,24 @@ function compares two times in | |||
62 | .Ar tm1 | 65 | .Ar tm1 |
63 | and | 66 | and |
64 | .Ar tm2 . | 67 | .Ar tm2 . |
68 | .Pp | ||
69 | The function | ||
70 | .Fn ASN1_TIME_set_tm | ||
71 | sets the | ||
72 | .Vt ASN1_TIME | ||
73 | structure | ||
74 | .Fa s | ||
75 | to the time represented by the | ||
76 | .Vt strict tm | ||
77 | value pointed to by | ||
78 | .Fa tm . | ||
79 | If | ||
80 | .Fa s | ||
81 | is | ||
82 | .Dv NULL , | ||
83 | a new | ||
84 | .Vt ASN1_TIME | ||
85 | structure is allocated and returned. | ||
65 | .Sh RETURN VALUES | 86 | .Sh RETURN VALUES |
66 | .Fn ASN1_parse_time | 87 | .Fn ASN1_parse_time |
67 | returns | 88 | returns |
@@ -97,3 +118,10 @@ is greater than | |||
97 | is the same as | 118 | is the same as |
98 | .Ar tm2 . | 119 | .Ar tm2 . |
99 | .El | 120 | .El |
121 | .Pp | ||
122 | .Fn ASN1_TIME_set_tm | ||
123 | returns a pointer to an | ||
124 | .Vt ASN1_TIME | ||
125 | structure or | ||
126 | .Dv NULL | ||
127 | if an error occurred. | ||