Coverage Report

Created: 2026-04-09 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl36/crypto/x509/v3_timespec.c
Line
Count
Source
1
/*
2
 * Copyright 2024-2026 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
#include <stdio.h>
11
#include <openssl/asn1t.h>
12
#include <openssl/x509v3.h>
13
#include <crypto/asn1.h>
14
#include "ext_dat.h"
15
16
static const char *WEEKDAY_NAMES[7] = {
17
    "SUN",
18
    "MON",
19
    "TUE",
20
    "WED",
21
    "THU",
22
    "FRI",
23
    "SAT"
24
};
25
26
static const char *WEEK_NAMES[5] = {
27
    "first",
28
    "second",
29
    "third",
30
    "fourth",
31
    "final"
32
};
33
34
static const char *MONTH_NAMES[12] = {
35
    "JAN",
36
    "FEB",
37
    "MAR",
38
    "APR",
39
    "MAY",
40
    "JUN",
41
    "JUL",
42
    "AUG",
43
    "SEPT",
44
    "OCT",
45
    "NOV",
46
    "DEC"
47
};
48
49
ASN1_SEQUENCE(OSSL_TIME_SPEC_ABSOLUTE) = {
50
    ASN1_EXP_OPT(OSSL_TIME_SPEC_ABSOLUTE, startTime, ASN1_GENERALIZEDTIME, 0),
51
    ASN1_EXP_OPT(OSSL_TIME_SPEC_ABSOLUTE, endTime, ASN1_GENERALIZEDTIME, 1),
52
37.9k
} ASN1_SEQUENCE_END(OSSL_TIME_SPEC_ABSOLUTE)
53
37.9k
54
37.9k
ASN1_SEQUENCE(OSSL_DAY_TIME) = {
55
37.9k
    ASN1_EXP_OPT(OSSL_DAY_TIME, hour, ASN1_INTEGER, 0),
56
37.9k
    ASN1_EXP_OPT(OSSL_DAY_TIME, minute, ASN1_INTEGER, 1),
57
37.9k
    ASN1_EXP_OPT(OSSL_DAY_TIME, second, ASN1_INTEGER, 2),
58
37.9k
} ASN1_SEQUENCE_END(OSSL_DAY_TIME)
59
10.1k
60
10.1k
ASN1_SEQUENCE(OSSL_DAY_TIME_BAND) = {
61
10.1k
    ASN1_EXP_OPT(OSSL_DAY_TIME_BAND, startDayTime, OSSL_DAY_TIME, 0),
62
10.1k
    ASN1_EXP_OPT(OSSL_DAY_TIME_BAND, endDayTime, OSSL_DAY_TIME, 1),
63
42.5k
} ASN1_SEQUENCE_END(OSSL_DAY_TIME_BAND)
64
42.5k
65
42.5k
ASN1_CHOICE(OSSL_NAMED_DAY) = {
66
42.5k
    ASN1_SET_OF(OSSL_NAMED_DAY, choice.intNamedDays, ASN1_ENUMERATED),
67
42.5k
    ASN1_SIMPLE(OSSL_NAMED_DAY, choice.bitNamedDays, ASN1_BIT_STRING),
68
42.5k
} ASN1_CHOICE_END(OSSL_NAMED_DAY)
69
14.4k
70
14.4k
ASN1_CHOICE(OSSL_TIME_SPEC_X_DAY_OF) = {
71
14.4k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.first, OSSL_NAMED_DAY, 1),
72
14.4k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.second, OSSL_NAMED_DAY, 2),
73
14.4k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.third, OSSL_NAMED_DAY, 3),
74
14.4k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.fourth, OSSL_NAMED_DAY, 4),
75
14.4k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.fifth, OSSL_NAMED_DAY, 5),
76
16.3k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_X_DAY_OF)
77
16.3k
78
16.3k
ASN1_CHOICE(OSSL_TIME_SPEC_DAY) = {
79
16.3k
    ASN1_SET_OF(OSSL_TIME_SPEC_DAY, choice.intDay, ASN1_INTEGER),
80
16.3k
    ASN1_SIMPLE(OSSL_TIME_SPEC_DAY, choice.bitDay, ASN1_BIT_STRING),
81
16.3k
    ASN1_SIMPLE(OSSL_TIME_SPEC_DAY, choice.dayOf, OSSL_TIME_SPEC_X_DAY_OF),
82
315k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_DAY)
83
315k
84
315k
ASN1_CHOICE(OSSL_TIME_SPEC_WEEKS) = {
85
315k
    ASN1_SIMPLE(OSSL_TIME_SPEC_WEEKS, choice.allWeeks, ASN1_NULL),
86
315k
    ASN1_SET_OF(OSSL_TIME_SPEC_WEEKS, choice.intWeek, ASN1_INTEGER),
87
315k
    ASN1_SIMPLE(OSSL_TIME_SPEC_WEEKS, choice.bitWeek, ASN1_BIT_STRING),
88
315k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_WEEKS)
89
312k
90
312k
ASN1_CHOICE(OSSL_TIME_SPEC_MONTH) = {
91
312k
    ASN1_SIMPLE(OSSL_TIME_SPEC_MONTH, choice.allMonths, ASN1_NULL),
92
312k
    ASN1_SET_OF(OSSL_TIME_SPEC_MONTH, choice.intMonth, ASN1_INTEGER),
93
312k
    ASN1_SIMPLE(OSSL_TIME_SPEC_MONTH, choice.bitMonth, ASN1_BIT_STRING),
94
312k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_MONTH)
95
312k
96
312k
ASN1_SEQUENCE(OSSL_TIME_PERIOD) = {
97
312k
    ASN1_EXP_SET_OF_OPT(OSSL_TIME_PERIOD, timesOfDay, OSSL_DAY_TIME_BAND, 0),
98
312k
    ASN1_EXP_OPT(OSSL_TIME_PERIOD, days, OSSL_TIME_SPEC_DAY, 1),
99
312k
    ASN1_EXP_OPT(OSSL_TIME_PERIOD, weeks, OSSL_TIME_SPEC_WEEKS, 2),
100
312k
    ASN1_EXP_OPT(OSSL_TIME_PERIOD, months, OSSL_TIME_SPEC_MONTH, 3),
101
312k
    ASN1_EXP_SET_OF_OPT(OSSL_TIME_PERIOD, years, ASN1_INTEGER, 4),
102
312k
} ASN1_SEQUENCE_END(OSSL_TIME_PERIOD)
103
83.8k
104
83.8k
ASN1_CHOICE(OSSL_TIME_SPEC_TIME) = {
105
83.8k
    ASN1_SIMPLE(OSSL_TIME_SPEC_TIME, choice.absolute, OSSL_TIME_SPEC_ABSOLUTE),
106
83.8k
    ASN1_SET_OF(OSSL_TIME_SPEC_TIME, choice.periodic, OSSL_TIME_PERIOD)
107
207k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_TIME)
108
207k
109
207k
ASN1_SEQUENCE(OSSL_TIME_SPEC) = {
110
207k
    ASN1_SIMPLE(OSSL_TIME_SPEC, time, OSSL_TIME_SPEC_TIME),
111
207k
    ASN1_OPT(OSSL_TIME_SPEC, notThisTime, ASN1_FBOOLEAN),
112
207k
    ASN1_OPT(OSSL_TIME_SPEC, timeZone, ASN1_INTEGER),
113
207k
} ASN1_SEQUENCE_END(OSSL_TIME_SPEC)
114
59.4k
115
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_DAY_TIME)
116
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_DAY_TIME_BAND)
117
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_DAY)
118
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_WEEKS)
119
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_MONTH)
120
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_NAMED_DAY)
121
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_X_DAY_OF)
122
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_ABSOLUTE)
123
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_TIME)
124
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC)
125
59.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_PERIOD)
126
59.4k
127
59.4k
static int i2r_OSSL_TIME_SPEC_ABSOLUTE(X509V3_EXT_METHOD *method,
128
59.4k
    OSSL_TIME_SPEC_ABSOLUTE *time,
129
59.4k
    BIO *out, int indent)
130
59.4k
{
131
3.73k
    if (time->startTime != NULL && time->endTime != NULL) {
132
0
        if (!BIO_puts(out, "Any time between "))
133
0
            return 0;
134
0
        if (!ossl_asn1_time_print_ex(out, time->startTime, 0))
135
0
            return 0;
136
0
        if (!BIO_puts(out, " and "))
137
0
            return 0;
138
0
        if (!ossl_asn1_time_print_ex(out, time->endTime, 0))
139
0
            return 0;
140
3.73k
    } else if (time->startTime != NULL) {
141
12
        if (!BIO_puts(out, "Any time after "))
142
0
            return 0;
143
12
        if (!ossl_asn1_time_print_ex(out, time->startTime, 0))
144
0
            return 0;
145
12
        if (BIO_printf(out, "%.*s", time->startTime->length, time->startTime->data) <= 0)
146
3
            return 0;
147
3.72k
    } else if (time->endTime != NULL) {
148
3
        if (!BIO_puts(out, "Any time until "))
149
0
            return 0;
150
3
        if (!ossl_asn1_time_print_ex(out, time->endTime, 0))
151
0
            return 0;
152
3.72k
    } else { /* Invalid: there must be SOME time specified. */
153
3.72k
        return BIO_puts(out, "INVALID (EMPTY)");
154
3.72k
    }
155
12
    return 1;
156
3.73k
}
157
158
static int i2r_OSSL_DAY_TIME(X509V3_EXT_METHOD *method,
159
    OSSL_DAY_TIME *dt,
160
    BIO *out, int indent)
161
107
{
162
107
    int64_t h = 0;
163
107
    int64_t m = 0;
164
107
    int64_t s = 0;
165
166
107
    if (!dt->hour || !ASN1_INTEGER_get_int64(&h, dt->hour))
167
107
        return 0;
168
0
    if (dt->minute && !ASN1_INTEGER_get_int64(&m, dt->minute))
169
0
        return 0;
170
0
    if (dt->second && !ASN1_INTEGER_get_int64(&s, dt->second))
171
0
        return 0;
172
0
    return BIO_printf(out, "%02lld:%02lld:%02lld",
173
0
               (long long int)h, (long long int)m, (long long int)s)
174
0
        > 0;
175
0
}
176
177
static int i2r_OSSL_DAY_TIME_BAND(X509V3_EXT_METHOD *method,
178
    OSSL_DAY_TIME_BAND *band,
179
    BIO *out, int indent)
180
1.13k
{
181
1.13k
    if (band->startDayTime) {
182
35
        if (!i2r_OSSL_DAY_TIME(method, band->startDayTime, out, indent))
183
35
            return 0;
184
1.09k
    } else if (!BIO_puts(out, "00:00:00")) {
185
0
        return 0;
186
0
    }
187
1.09k
    if (!BIO_puts(out, " - "))
188
0
        return 0;
189
1.09k
    if (band->endDayTime) {
190
72
        if (!i2r_OSSL_DAY_TIME(method, band->endDayTime, out, indent))
191
72
            return 0;
192
1.02k
    } else if (!BIO_puts(out, "23:59:59")) {
193
0
        return 0;
194
0
    }
195
1.02k
    return 1;
196
1.09k
}
197
198
static int print_int_month(BIO *out, int64_t month)
199
9.54k
{
200
9.54k
    switch (month) {
201
8.40k
    case (OSSL_TIME_SPEC_INT_MONTH_JAN):
202
8.40k
        return BIO_puts(out, "JAN");
203
130
    case (OSSL_TIME_SPEC_INT_MONTH_FEB):
204
130
        return BIO_puts(out, "FEB");
205
15
    case (OSSL_TIME_SPEC_INT_MONTH_MAR):
206
15
        return BIO_puts(out, "MAR");
207
15
    case (OSSL_TIME_SPEC_INT_MONTH_APR):
208
15
        return BIO_puts(out, "APR");
209
23
    case (OSSL_TIME_SPEC_INT_MONTH_MAY):
210
23
        return BIO_puts(out, "MAY");
211
6
    case (OSSL_TIME_SPEC_INT_MONTH_JUN):
212
6
        return BIO_puts(out, "JUN");
213
9
    case (OSSL_TIME_SPEC_INT_MONTH_JUL):
214
9
        return BIO_puts(out, "JUL");
215
18
    case (OSSL_TIME_SPEC_INT_MONTH_AUG):
216
18
        return BIO_puts(out, "AUG");
217
22
    case (OSSL_TIME_SPEC_INT_MONTH_SEP):
218
22
        return BIO_puts(out, "SEP");
219
27
    case (OSSL_TIME_SPEC_INT_MONTH_OCT):
220
27
        return BIO_puts(out, "OCT");
221
12
    case (OSSL_TIME_SPEC_INT_MONTH_NOV):
222
12
        return BIO_puts(out, "NOV");
223
24
    case (OSSL_TIME_SPEC_INT_MONTH_DEC):
224
24
        return BIO_puts(out, "DEC");
225
841
    default:
226
841
        return 0;
227
9.54k
    }
228
0
    return 0;
229
9.54k
}
230
231
static int print_bit_month(BIO *out, ASN1_BIT_STRING *bs)
232
848
{
233
848
    int i = OSSL_TIME_SPEC_BIT_MONTH_JAN;
234
848
    int j = 0;
235
236
11.0k
    for (; i <= OSSL_TIME_SPEC_BIT_MONTH_DEC; i++) {
237
10.1k
        if (ASN1_BIT_STRING_get_bit(bs, i)) {
238
4.70k
            if (j > 0 && !BIO_puts(out, ", "))
239
0
                return 0;
240
4.70k
            j++;
241
4.70k
            if (!BIO_puts(out, MONTH_NAMES[i]))
242
0
                return 0;
243
4.70k
        }
244
10.1k
    }
245
848
    return 1;
246
848
}
247
248
/*
249
 * It might seem like you could just print the bits of the string numerically,
250
 * but the fifth bit has the special meaning of "the final week" imputed to it
251
 * by the text of ITU-T Recommendation X.520.
252
 */
253
static int print_bit_week(BIO *out, ASN1_BIT_STRING *bs)
254
426
{
255
426
    int i = OSSL_TIME_SPEC_BIT_WEEKS_1;
256
426
    int j = 0;
257
258
2.55k
    for (; i <= OSSL_TIME_SPEC_BIT_WEEKS_5; i++) {
259
2.13k
        if (ASN1_BIT_STRING_get_bit(bs, i)) {
260
1.47k
            if (j > 0 && !BIO_puts(out, ", "))
261
0
                return 0;
262
1.47k
            j++;
263
1.47k
            if (!BIO_puts(out, WEEK_NAMES[i]))
264
0
                return 0;
265
1.47k
        }
266
2.13k
    }
267
426
    return 1;
268
426
}
269
270
static int print_day_of_week(BIO *out, ASN1_BIT_STRING *bs)
271
3.03k
{
272
3.03k
    int i = OSSL_TIME_SPEC_DAY_BIT_SUN;
273
3.03k
    int j = 0;
274
275
24.3k
    for (; i <= OSSL_TIME_SPEC_DAY_BIT_SAT; i++) {
276
21.2k
        if (ASN1_BIT_STRING_get_bit(bs, i)) {
277
11.8k
            if (j > 0 && !BIO_puts(out, ", "))
278
0
                return 0;
279
11.8k
            j++;
280
11.8k
            if (!BIO_puts(out, WEEKDAY_NAMES[i]))
281
0
                return 0;
282
11.8k
        }
283
21.2k
    }
284
3.03k
    return 1;
285
3.03k
}
286
287
static int print_int_day_of_week(BIO *out, int64_t dow)
288
1
{
289
1
    switch (dow) {
290
0
    case (OSSL_TIME_SPEC_DAY_INT_SUN):
291
0
        return BIO_puts(out, "SUN");
292
0
    case (OSSL_TIME_SPEC_DAY_INT_MON):
293
0
        return BIO_puts(out, "MON");
294
0
    case (OSSL_TIME_SPEC_DAY_INT_TUE):
295
0
        return BIO_puts(out, "TUE");
296
0
    case (OSSL_TIME_SPEC_DAY_INT_WED):
297
0
        return BIO_puts(out, "WED");
298
0
    case (OSSL_TIME_SPEC_DAY_INT_THU):
299
0
        return BIO_puts(out, "THU");
300
0
    case (OSSL_TIME_SPEC_DAY_INT_FRI):
301
0
        return BIO_puts(out, "FRI");
302
0
    case (OSSL_TIME_SPEC_DAY_INT_SAT):
303
0
        return BIO_puts(out, "SAT");
304
1
    default:
305
1
        return 0;
306
1
    }
307
0
    return 0;
308
1
}
309
310
static int print_int_named_day(BIO *out, int64_t nd)
311
0
{
312
0
    switch (nd) {
313
0
    case (OSSL_NAMED_DAY_INT_SUN):
314
0
        return BIO_puts(out, "SUN");
315
0
    case (OSSL_NAMED_DAY_INT_MON):
316
0
        return BIO_puts(out, "MON");
317
0
    case (OSSL_NAMED_DAY_INT_TUE):
318
0
        return BIO_puts(out, "TUE");
319
0
    case (OSSL_NAMED_DAY_INT_WED):
320
0
        return BIO_puts(out, "WED");
321
0
    case (OSSL_NAMED_DAY_INT_THU):
322
0
        return BIO_puts(out, "THU");
323
0
    case (OSSL_NAMED_DAY_INT_FRI):
324
0
        return BIO_puts(out, "FRI");
325
0
    case (OSSL_NAMED_DAY_INT_SAT):
326
0
        return BIO_puts(out, "SAT");
327
0
    default:
328
0
        return 0;
329
0
    }
330
0
    return 0;
331
0
}
332
333
static int print_bit_named_day(BIO *out, ASN1_BIT_STRING *bs)
334
2.13k
{
335
2.13k
    return print_day_of_week(out, bs);
336
2.13k
}
337
338
static int i2r_OSSL_PERIOD(X509V3_EXT_METHOD *method,
339
    OSSL_TIME_PERIOD *p,
340
    BIO *out, int indent)
341
24.3k
{
342
24.3k
    int i;
343
24.3k
    OSSL_DAY_TIME_BAND *band;
344
24.3k
    ASN1_INTEGER *big_val;
345
24.3k
    int64_t small_val;
346
24.3k
    OSSL_NAMED_DAY *nd;
347
348
24.3k
    if (BIO_printf(out, "%*sPeriod:\n", indent, "") <= 0)
349
0
        return 0;
350
24.3k
    if (p->timesOfDay) {
351
316
        if (BIO_printf(out, "%*sDaytime bands:\n", indent + 4, "") <= 0)
352
0
            return 0;
353
1.34k
        for (i = 0; i < sk_OSSL_DAY_TIME_BAND_num(p->timesOfDay); i++) {
354
1.13k
            band = sk_OSSL_DAY_TIME_BAND_value(p->timesOfDay, i);
355
1.13k
            if (BIO_printf(out, "%*s", indent + 8, "") <= 0)
356
0
                return 0;
357
1.13k
            if (!i2r_OSSL_DAY_TIME_BAND(method, band, out, indent + 8))
358
107
                return 0;
359
1.02k
            if (!BIO_puts(out, "\n"))
360
0
                return 0;
361
1.02k
        }
362
316
    }
363
24.1k
    if (p->days) {
364
3.71k
        if (p->days->type == OSSL_TIME_SPEC_DAY_TYPE_INT) {
365
559
            if (p->weeks != NULL) {
366
73
                if (BIO_printf(out, "%*sDays of the week: ", indent + 4, "") <= 0)
367
0
                    return 0;
368
486
            } else if (p->months != NULL) {
369
27
                if (BIO_printf(out, "%*sDays of the month: ", indent + 4, "") <= 0)
370
0
                    return 0;
371
459
            } else if (p->years != NULL) {
372
18
                if (BIO_printf(out, "%*sDays of the year: ", indent + 4, "") <= 0)
373
0
                    return 0;
374
18
            }
375
3.15k
        } else {
376
3.15k
            if (BIO_printf(out, "%*sDays: ", indent + 4, "") <= 0)
377
0
                return 0;
378
3.15k
        }
379
380
3.71k
        switch (p->days->type) {
381
559
        case (OSSL_TIME_SPEC_DAY_TYPE_INT):
382
2.23k
            for (i = 0; i < sk_ASN1_INTEGER_num(p->days->choice.intDay); i++) {
383
1.77k
                big_val = sk_ASN1_INTEGER_value(p->days->choice.intDay, i);
384
1.77k
                if (!ASN1_INTEGER_get_int64(&small_val, big_val))
385
101
                    return 0;
386
1.67k
                if (i > 0 && !BIO_puts(out, ", "))
387
0
                    return 0;
388
                /* If weeks is defined, then print day of week by name. */
389
1.67k
                if (p->weeks != NULL) {
390
1
                    if (!print_int_day_of_week(out, small_val))
391
1
                        return 0;
392
1.67k
                } else if (BIO_printf(out, "%lld", (long long int)small_val) <= 0) {
393
0
                    return 0;
394
0
                }
395
1.67k
            }
396
457
            break;
397
905
        case (OSSL_TIME_SPEC_DAY_TYPE_BIT):
398
905
            if (!print_day_of_week(out, p->days->choice.bitDay))
399
0
                return 0;
400
905
            break;
401
2.25k
        case (OSSL_TIME_SPEC_DAY_TYPE_DAY_OF):
402
2.25k
            switch (p->days->choice.dayOf->type) {
403
259
            case (OSSL_TIME_SPEC_X_DAY_OF_FIRST):
404
259
                if (!BIO_puts(out, "FIRST "))
405
0
                    return 0;
406
259
                nd = p->days->choice.dayOf->choice.first;
407
259
                break;
408
133
            case (OSSL_TIME_SPEC_X_DAY_OF_SECOND):
409
133
                if (!BIO_puts(out, "SECOND "))
410
0
                    return 0;
411
133
                nd = p->days->choice.dayOf->choice.second;
412
133
                break;
413
1.76k
            case (OSSL_TIME_SPEC_X_DAY_OF_THIRD):
414
1.76k
                if (!BIO_puts(out, "THIRD "))
415
0
                    return 0;
416
1.76k
                nd = p->days->choice.dayOf->choice.third;
417
1.76k
                break;
418
55
            case (OSSL_TIME_SPEC_X_DAY_OF_FOURTH):
419
55
                if (!BIO_puts(out, "FOURTH "))
420
0
                    return 0;
421
55
                nd = p->days->choice.dayOf->choice.fourth;
422
55
                break;
423
44
            case (OSSL_TIME_SPEC_X_DAY_OF_FIFTH):
424
44
                if (!BIO_puts(out, "FIFTH "))
425
0
                    return 0;
426
44
                nd = p->days->choice.dayOf->choice.fifth;
427
44
                break;
428
0
            default:
429
0
                return 0;
430
2.25k
            }
431
2.25k
            switch (nd->type) {
432
121
            case (OSSL_NAMED_DAY_TYPE_INT):
433
121
                if (!ASN1_INTEGER_get_int64(&small_val, nd->choice.intNamedDays))
434
121
                    return 0;
435
0
                if (!print_int_named_day(out, small_val))
436
0
                    return 0;
437
0
                break;
438
2.13k
            case (OSSL_NAMED_DAY_TYPE_BIT):
439
2.13k
                if (!print_bit_named_day(out, nd->choice.bitNamedDays))
440
0
                    return 0;
441
2.13k
                break;
442
2.13k
            default:
443
0
                return 0;
444
2.25k
            }
445
2.13k
            break;
446
2.13k
        default:
447
0
            return 0;
448
3.71k
        }
449
3.49k
        if (!BIO_puts(out, "\n"))
450
0
            return 0;
451
3.49k
    }
452
23.9k
    if (p->weeks) {
453
738
        if (p->weeks->type == OSSL_TIME_SPEC_WEEKS_TYPE_INT) {
454
207
            if (p->months != NULL) {
455
22
                if (BIO_printf(out, "%*sWeeks of the month: ", indent + 4, "") <= 0)
456
0
                    return 0;
457
185
            } else if (p->years != NULL) {
458
3
                if (BIO_printf(out, "%*sWeeks of the year: ", indent + 4, "") <= 0)
459
0
                    return 0;
460
3
            }
461
531
        } else {
462
531
            if (BIO_printf(out, "%*sWeeks: ", indent + 4, "") <= 0)
463
0
                return 0;
464
531
        }
465
466
738
        switch (p->weeks->type) {
467
105
        case (OSSL_TIME_SPEC_WEEKS_TYPE_ALL):
468
105
            if (!BIO_puts(out, "ALL"))
469
0
                return 0;
470
105
            break;
471
207
        case (OSSL_TIME_SPEC_WEEKS_TYPE_INT):
472
561
            for (i = 0; i < sk_ASN1_INTEGER_num(p->weeks->choice.intWeek); i++) {
473
393
                big_val = sk_ASN1_INTEGER_value(p->weeks->choice.intWeek, i);
474
393
                if (!ASN1_INTEGER_get_int64(&small_val, big_val))
475
39
                    return 0;
476
354
                if (i > 0 && !BIO_puts(out, ", "))
477
0
                    return 0;
478
354
                if (!BIO_printf(out, "%lld", (long long int)small_val))
479
0
                    return 0;
480
354
            }
481
168
            break;
482
426
        case (OSSL_TIME_SPEC_WEEKS_TYPE_BIT):
483
426
            if (!print_bit_week(out, p->weeks->choice.bitWeek))
484
0
                return 0;
485
426
            break;
486
426
        default:
487
0
            return 0;
488
738
        }
489
699
        if (!BIO_puts(out, "\n"))
490
0
            return 0;
491
699
    }
492
23.9k
    if (p->months) {
493
3.68k
        if (BIO_printf(out, "%*sMonths: ", indent + 4, "") <= 0)
494
0
            return 0;
495
3.68k
        switch (p->months->type) {
496
235
        case (OSSL_TIME_SPEC_MONTH_TYPE_ALL):
497
235
            if (!BIO_puts(out, "ALL"))
498
0
                return 0;
499
235
            break;
500
2.60k
        case (OSSL_TIME_SPEC_MONTH_TYPE_INT):
501
11.3k
            for (i = 0; i < sk_ASN1_INTEGER_num(p->months->choice.intMonth); i++) {
502
9.66k
                big_val = sk_ASN1_INTEGER_value(p->months->choice.intMonth, i);
503
9.66k
                if (!ASN1_INTEGER_get_int64(&small_val, big_val))
504
125
                    return 0;
505
9.54k
                if (i > 0 && !BIO_puts(out, ", "))
506
0
                    return 0;
507
9.54k
                if (!print_int_month(out, small_val))
508
841
                    return 0;
509
9.54k
            }
510
1.63k
            break;
511
1.63k
        case (OSSL_TIME_SPEC_MONTH_TYPE_BIT):
512
848
            if (!print_bit_month(out, p->months->choice.bitMonth))
513
0
                return 0;
514
848
            break;
515
848
        default:
516
0
            return 0;
517
3.68k
        }
518
2.71k
        if (!BIO_puts(out, "\n"))
519
0
            return 0;
520
2.71k
    }
521
22.9k
    if (p->years) {
522
1.02k
        if (BIO_printf(out, "%*sYears: ", indent + 4, "") <= 0)
523
0
            return 0;
524
3.20k
        for (i = 0; i < sk_ASN1_INTEGER_num(p->years); i++) {
525
2.34k
            big_val = sk_ASN1_INTEGER_value(p->years, i);
526
2.34k
            if (!ASN1_INTEGER_get_int64(&small_val, big_val))
527
169
                return 0;
528
2.17k
            if (i > 0 && !BIO_puts(out, ", "))
529
0
                return 0;
530
2.17k
            if (BIO_printf(out, "%04lld", (long long int)small_val) <= 0)
531
0
                return 0;
532
2.17k
        }
533
1.02k
    }
534
22.8k
    return 1;
535
22.9k
}
536
537
static int i2r_OSSL_TIME_SPEC_TIME(X509V3_EXT_METHOD *method,
538
    OSSL_TIME_SPEC_TIME *time,
539
    BIO *out, int indent)
540
17.2k
{
541
17.2k
    OSSL_TIME_PERIOD *tp;
542
17.2k
    int i;
543
544
17.2k
    switch (time->type) {
545
3.73k
    case (OSSL_TIME_SPEC_TIME_TYPE_ABSOLUTE):
546
3.73k
        if (BIO_printf(out, "%*sAbsolute: ", indent, "") <= 0)
547
0
            return 0;
548
3.73k
        if (i2r_OSSL_TIME_SPEC_ABSOLUTE(method, time->choice.absolute, out, indent + 4) <= 0)
549
3
            return 0;
550
3.73k
        return BIO_puts(out, "\n");
551
13.4k
    case (OSSL_TIME_SPEC_TIME_TYPE_PERIODIC):
552
13.4k
        if (BIO_printf(out, "%*sPeriodic:\n", indent, "") <= 0)
553
0
            return 0;
554
36.3k
        for (i = 0; i < sk_OSSL_TIME_PERIOD_num(time->choice.periodic); i++) {
555
24.3k
            if (i > 0 && !BIO_puts(out, "\n"))
556
0
                return 0;
557
24.3k
            tp = sk_OSSL_TIME_PERIOD_value(time->choice.periodic, i);
558
24.3k
            if (!i2r_OSSL_PERIOD(method, tp, out, indent + 4))
559
1.50k
                return 0;
560
24.3k
        }
561
11.9k
        return BIO_puts(out, "\n");
562
0
    default:
563
0
        return 0;
564
17.2k
    }
565
0
    return 0;
566
17.2k
}
567
568
static int i2r_OSSL_TIME_SPEC(X509V3_EXT_METHOD *method,
569
    OSSL_TIME_SPEC *time,
570
    BIO *out, int indent)
571
17.8k
{
572
17.8k
    int64_t tz;
573
574
17.8k
    if (time->timeZone) {
575
3.03k
        if (ASN1_INTEGER_get_int64(&tz, time->timeZone) != 1)
576
572
            return 0;
577
2.46k
        if (BIO_printf(out, "%*sTimezone: UTC%+03lld:00\n", indent, "", (long long int)tz) <= 0)
578
0
            return 0;
579
2.46k
    }
580
17.2k
    if (time->notThisTime > 0) {
581
605
        if (BIO_printf(out, "%*sNOT this time:\n", indent, "") <= 0)
582
0
            return 0;
583
16.6k
    } else if (BIO_printf(out, "%*sTime:\n", indent, "") <= 0) {
584
0
        return 0;
585
0
    }
586
17.2k
    return i2r_OSSL_TIME_SPEC_TIME(method, time->time, out, indent + 4);
587
17.2k
}
588
589
const X509V3_EXT_METHOD ossl_v3_time_specification = {
590
    NID_time_specification, X509V3_EXT_MULTILINE,
591
    ASN1_ITEM_ref(OSSL_TIME_SPEC),
592
    0, 0, 0, 0,
593
    0, 0,
594
    0,
595
    0,
596
    (X509V3_EXT_I2R)i2r_OSSL_TIME_SPEC,
597
    NULL,
598
    NULL
599
};