]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/asn1/a_gentm.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
11 * GENERALIZEDTIME implementation. Based on UTCTIME
16 #include "internal/cryptlib.h"
17 #include <openssl/asn1.h>
18 #include "asn1_local.h"
20 /* This is the primary function used to parse ASN1_GENERALIZEDTIME */
21 int asn1_generalizedtime_to_tm(struct tm
*tm
, const ASN1_GENERALIZEDTIME
*d
)
23 /* wrapper around asn1_time_to_tm */
24 if (d
->type
!= V_ASN1_GENERALIZEDTIME
)
26 return asn1_time_to_tm(tm
, d
);
29 int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME
*d
)
31 return asn1_generalizedtime_to_tm(NULL
, d
);
34 int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME
*s
, const char *str
)
36 ASN1_GENERALIZEDTIME t
;
38 t
.type
= V_ASN1_GENERALIZEDTIME
;
39 t
.length
= strlen(str
);
40 t
.data
= (unsigned char *)str
;
43 if (!ASN1_GENERALIZEDTIME_check(&t
))
46 if (s
!= NULL
&& !ASN1_STRING_copy(s
, &t
))
52 ASN1_GENERALIZEDTIME
*ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME
*s
,
55 return ASN1_GENERALIZEDTIME_adj(s
, t
, 0, 0);
58 ASN1_GENERALIZEDTIME
*ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME
*s
,
59 time_t t
, int offset_day
,
65 ts
= OPENSSL_gmtime(&t
, &data
);
69 if (offset_day
|| offset_sec
) {
70 if (!OPENSSL_gmtime_adj(ts
, offset_day
, offset_sec
))
74 return asn1_time_from_tm(s
, ts
, V_ASN1_GENERALIZEDTIME
);
77 int ASN1_GENERALIZEDTIME_print(BIO
*bp
, const ASN1_GENERALIZEDTIME
*tm
)
79 if (tm
->type
!= V_ASN1_GENERALIZEDTIME
)
81 return ASN1_TIME_print(bp
, tm
);