/src/openssl30/crypto/asn1/a_gentm.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 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 | 
| 8 |  |  */ | 
| 9 |  |  | 
| 10 |  | /* | 
| 11 |  |  * GENERALIZEDTIME implementation. Based on UTCTIME | 
| 12 |  |  */ | 
| 13 |  |  | 
| 14 |  | #include <stdio.h> | 
| 15 |  | #include <time.h> | 
| 16 |  | #include "internal/cryptlib.h" | 
| 17 |  | #include <openssl/asn1.h> | 
| 18 |  | #include "asn1_local.h" | 
| 19 |  | #include <openssl/asn1t.h> | 
| 20 |  |  | 
| 21 |  | IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_GENERALIZEDTIME) | 
| 22 |  |  | 
| 23 |  | /* This is the primary function used to parse ASN1_GENERALIZEDTIME */ | 
| 24 |  | static int asn1_generalizedtime_to_tm(struct tm *tm, | 
| 25 |  |                                       const ASN1_GENERALIZEDTIME *d) | 
| 26 | 27.7k | { | 
| 27 |  |     /* wrapper around ossl_asn1_time_to_tm */ | 
| 28 | 27.7k |     if (d->type != V_ASN1_GENERALIZEDTIME) | 
| 29 | 0 |         return 0; | 
| 30 | 27.7k |     return ossl_asn1_time_to_tm(tm, d); | 
| 31 | 27.7k | } | 
| 32 |  |  | 
| 33 |  | int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d) | 
| 34 | 45.2k | { | 
| 35 | 45.2k |     return asn1_generalizedtime_to_tm(NULL, d); | 
| 36 | 45.2k | } | 
| 37 |  |  | 
| 38 |  | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) | 
| 39 | 45.2k | { | 
| 40 | 45.2k |     ASN1_GENERALIZEDTIME t; | 
| 41 |  |  | 
| 42 | 45.2k |     t.type = V_ASN1_GENERALIZEDTIME; | 
| 43 | 45.2k |     t.length = strlen(str); | 
| 44 | 45.2k |     t.data = (unsigned char *)str; | 
| 45 | 45.2k |     t.flags = 0; | 
| 46 |  |  | 
| 47 | 45.2k |     if (!ASN1_GENERALIZEDTIME_check(&t)) | 
| 48 | 17.0k |         return 0; | 
| 49 |  |  | 
| 50 | 28.1k |     if (s != NULL && !ASN1_STRING_copy(s, &t)) | 
| 51 | 0 |         return 0; | 
| 52 |  |  | 
| 53 | 28.1k |     return 1; | 
| 54 | 28.1k | } | 
| 55 |  |  | 
| 56 |  | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, | 
| 57 |  |                                                time_t t) | 
| 58 | 12.4k | { | 
| 59 | 12.4k |     return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); | 
| 60 | 12.4k | } | 
| 61 |  |  | 
| 62 |  | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, | 
| 63 |  |                                                time_t t, int offset_day, | 
| 64 |  |                                                long offset_sec) | 
| 65 | 57.6k | { | 
| 66 | 57.6k |     struct tm *ts; | 
| 67 | 57.6k |     struct tm data; | 
| 68 |  |  | 
| 69 | 57.6k |     ts = OPENSSL_gmtime(&t, &data); | 
| 70 | 57.6k |     if (ts == NULL) | 
| 71 | 0 |         return NULL; | 
| 72 |  |  | 
| 73 | 57.6k |     if (offset_day || offset_sec) { | 
| 74 | 39.8k |         if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 
| 75 | 17.0k |             return NULL; | 
| 76 | 39.8k |     } | 
| 77 |  |  | 
| 78 | 40.6k |     return ossl_asn1_time_from_tm(s, ts, V_ASN1_GENERALIZEDTIME); | 
| 79 | 57.6k | } | 
| 80 |  |  | 
| 81 |  | int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm) | 
| 82 | 91.6k | { | 
| 83 | 91.6k |     if (tm->type != V_ASN1_GENERALIZEDTIME) | 
| 84 | 0 |         return 0; | 
| 85 | 91.6k |     return ASN1_TIME_print(bp, tm); | 
| 86 | 91.6k | } |