11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
51cb0ef41Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at
71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include <stdio.h>
111cb0ef41Sopenharmony_ci#include "internal/cryptlib.h"
121cb0ef41Sopenharmony_ci#include <openssl/asn1.h>
131cb0ef41Sopenharmony_ci#include <openssl/asn1t.h>
141cb0ef41Sopenharmony_ci#include <openssl/x509v3.h>
151cb0ef41Sopenharmony_ci#include "ext_dat.h"
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cistatic int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
181cb0ef41Sopenharmony_ci                                 PKEY_USAGE_PERIOD *usage, BIO *out,
191cb0ef41Sopenharmony_ci                                 int indent);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciconst X509V3_EXT_METHOD ossl_v3_pkey_usage_period = {
221cb0ef41Sopenharmony_ci    NID_private_key_usage_period, 0, ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
231cb0ef41Sopenharmony_ci    0, 0, 0, 0,
241cb0ef41Sopenharmony_ci    0, 0, 0, 0,
251cb0ef41Sopenharmony_ci    (X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL,
261cb0ef41Sopenharmony_ci    NULL
271cb0ef41Sopenharmony_ci};
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciASN1_SEQUENCE(PKEY_USAGE_PERIOD) = {
301cb0ef41Sopenharmony_ci        ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notBefore, ASN1_GENERALIZEDTIME, 0),
311cb0ef41Sopenharmony_ci        ASN1_IMP_OPT(PKEY_USAGE_PERIOD, notAfter, ASN1_GENERALIZEDTIME, 1)
321cb0ef41Sopenharmony_ci} ASN1_SEQUENCE_END(PKEY_USAGE_PERIOD)
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ciIMPLEMENT_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cistatic int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
371cb0ef41Sopenharmony_ci                                 PKEY_USAGE_PERIOD *usage, BIO *out,
381cb0ef41Sopenharmony_ci                                 int indent)
391cb0ef41Sopenharmony_ci{
401cb0ef41Sopenharmony_ci    BIO_printf(out, "%*s", indent, "");
411cb0ef41Sopenharmony_ci    if (usage->notBefore) {
421cb0ef41Sopenharmony_ci        BIO_write(out, "Not Before: ", 12);
431cb0ef41Sopenharmony_ci        ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
441cb0ef41Sopenharmony_ci        if (usage->notAfter)
451cb0ef41Sopenharmony_ci            BIO_write(out, ", ", 2);
461cb0ef41Sopenharmony_ci    }
471cb0ef41Sopenharmony_ci    if (usage->notAfter) {
481cb0ef41Sopenharmony_ci        BIO_write(out, "Not After: ", 11);
491cb0ef41Sopenharmony_ci        ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
501cb0ef41Sopenharmony_ci    }
511cb0ef41Sopenharmony_ci    return 1;
521cb0ef41Sopenharmony_ci}
53