1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#include <stdio.h>
11e1051a39Sopenharmony_ci#include "internal/cryptlib.h"
12e1051a39Sopenharmony_ci#include <openssl/x509v3.h>
13e1051a39Sopenharmony_ci#include "ext_dat.h"
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_cistatic ENUMERATED_NAMES crl_reasons[] = {
16e1051a39Sopenharmony_ci    {CRL_REASON_UNSPECIFIED, "Unspecified", "unspecified"},
17e1051a39Sopenharmony_ci    {CRL_REASON_KEY_COMPROMISE, "Key Compromise", "keyCompromise"},
18e1051a39Sopenharmony_ci    {CRL_REASON_CA_COMPROMISE, "CA Compromise", "CACompromise"},
19e1051a39Sopenharmony_ci    {CRL_REASON_AFFILIATION_CHANGED, "Affiliation Changed",
20e1051a39Sopenharmony_ci     "affiliationChanged"},
21e1051a39Sopenharmony_ci    {CRL_REASON_SUPERSEDED, "Superseded", "superseded"},
22e1051a39Sopenharmony_ci    {CRL_REASON_CESSATION_OF_OPERATION,
23e1051a39Sopenharmony_ci     "Cessation Of Operation", "cessationOfOperation"},
24e1051a39Sopenharmony_ci    {CRL_REASON_CERTIFICATE_HOLD, "Certificate Hold", "certificateHold"},
25e1051a39Sopenharmony_ci    {CRL_REASON_REMOVE_FROM_CRL, "Remove From CRL", "removeFromCRL"},
26e1051a39Sopenharmony_ci    {CRL_REASON_PRIVILEGE_WITHDRAWN, "Privilege Withdrawn",
27e1051a39Sopenharmony_ci     "privilegeWithdrawn"},
28e1051a39Sopenharmony_ci    {CRL_REASON_AA_COMPROMISE, "AA Compromise", "AACompromise"},
29e1051a39Sopenharmony_ci    {-1, NULL, NULL}
30e1051a39Sopenharmony_ci};
31e1051a39Sopenharmony_ci
32e1051a39Sopenharmony_ciconst X509V3_EXT_METHOD ossl_v3_crl_reason = {
33e1051a39Sopenharmony_ci    NID_crl_reason, 0, ASN1_ITEM_ref(ASN1_ENUMERATED),
34e1051a39Sopenharmony_ci    0, 0, 0, 0,
35e1051a39Sopenharmony_ci    (X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
36e1051a39Sopenharmony_ci    0,
37e1051a39Sopenharmony_ci    0, 0, 0, 0,
38e1051a39Sopenharmony_ci    crl_reasons
39e1051a39Sopenharmony_ci};
40e1051a39Sopenharmony_ci
41e1051a39Sopenharmony_cichar *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
42e1051a39Sopenharmony_ci                                const ASN1_ENUMERATED *e)
43e1051a39Sopenharmony_ci{
44e1051a39Sopenharmony_ci    ENUMERATED_NAMES *enam;
45e1051a39Sopenharmony_ci    long strval;
46e1051a39Sopenharmony_ci
47e1051a39Sopenharmony_ci    strval = ASN1_ENUMERATED_get(e);
48e1051a39Sopenharmony_ci    for (enam = method->usr_data; enam->lname; enam++) {
49e1051a39Sopenharmony_ci        if (strval == enam->bitnum)
50e1051a39Sopenharmony_ci            return OPENSSL_strdup(enam->lname);
51e1051a39Sopenharmony_ci    }
52e1051a39Sopenharmony_ci    return i2s_ASN1_ENUMERATED(method, e);
53e1051a39Sopenharmony_ci}
54