]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/asn1/a_utctm.c
2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include "internal/cryptlib.h"
13 #include <openssl/asn1.h>
14 #include "asn1_locl.h"
16 /* This is the primary function used to parse ASN1_UTCTIME */
17 int asn1_utctime_to_tm(struct tm
*tm
, const ASN1_UTCTIME
*d
)
19 /* wrapper around asn1_time_to_tm */
20 if (d
->type
!= V_ASN1_UTCTIME
)
22 return asn1_time_to_tm(tm
, d
);
25 int ASN1_UTCTIME_check(const ASN1_UTCTIME
*d
)
27 return asn1_utctime_to_tm(NULL
, d
);
30 /* Sets the string via simple copy without cleaning it up */
31 int ASN1_UTCTIME_set_string(ASN1_UTCTIME
*s
, const char *str
)
35 t
.type
= V_ASN1_UTCTIME
;
36 t
.length
= strlen(str
);
37 t
.data
= (unsigned char *)str
;
40 if (!ASN1_UTCTIME_check(&t
))
43 if (s
!= NULL
&& !ASN1_STRING_copy(s
, &t
))
49 ASN1_UTCTIME
*ASN1_UTCTIME_set(ASN1_UTCTIME
*s
, time_t t
)
51 return ASN1_UTCTIME_adj(s
, t
, 0, 0);
54 ASN1_UTCTIME
*ASN1_UTCTIME_adj(ASN1_UTCTIME
*s
, time_t t
,
55 int offset_day
, long offset_sec
)
60 ts
= OPENSSL_gmtime(&t
, &data
);
64 if (offset_day
|| offset_sec
) {
65 if (!OPENSSL_gmtime_adj(ts
, offset_day
, offset_sec
))
69 return asn1_time_from_tm(s
, ts
, V_ASN1_UTCTIME
);
72 int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME
*s
, time_t t
)
77 if (!asn1_utctime_to_tm(&stm
, s
))
80 if (OPENSSL_gmtime(&t
, &ttm
) == NULL
)
83 if (!OPENSSL_gmtime_diff(&day
, &sec
, &ttm
, &stm
))
86 if (day
> 0 || sec
> 0)
88 if (day
< 0 || sec
< 0)
93 int ASN1_UTCTIME_print(BIO
*bp
, const ASN1_UTCTIME
*tm
)
95 if (tm
->type
!= V_ASN1_UTCTIME
)
97 return ASN1_TIME_print(bp
, tm
);