Repository: randombit/botan
Pull request #3245 (2023-02-01 22:39:55)

CamelCase the CRL_Code enum
Also remove several non-wire variants which are no longer used.


Patch:
diff --git a/src/lib/x509/crl_ent.cpp b/src/lib/x509/crl_ent.cpp
index affae3184..296fcd729 100644
--- a/src/lib/x509/crl_ent.cpp
+++ b/src/lib/x509/crl_ent.cpp
@@ -18,7 +18,7 @@ struct CRL_Entry_Data
    {
    std::vector<uint8_t> m_serial;
    X509_Time m_time;
-   CRL_Code m_reason = CRL_Code::UNSPECIFIED;
+   CRL_Code m_reason = CRL_Code::Unspecified;
    Extensions m_extensions;
    };
 
@@ -32,7 +32,7 @@ CRL_Entry::CRL_Entry(const X509_Certificate& cert, CRL_Code why)
    m_data->m_time = X509_Time(std::chrono::system_clock::now());
    m_data->m_reason = why;
 
-   if(why != CRL_Code::UNSPECIFIED)
+   if(why != CRL_Code::Unspecified)
       {
       m_data->m_extensions.add(std::make_unique<Cert_Extension::CRL_ReasonCode>(why));
       }
@@ -97,7 +97,7 @@ void CRL_Entry::decode_from(BER_Decoder& source)
          }
       else
          {
-         data->m_reason = CRL_Code::UNSPECIFIED;
+         data->m_reason = CRL_Code::Unspecified;
          }
       }
 
diff --git a/src/lib/x509/pkix_enums.h b/src/lib/x509/pkix_enums.h
index 7d7668260..155060c91 100644
--- a/src/lib/x509/pkix_enums.h
+++ b/src/lib/x509/pkix_enums.h
@@ -188,21 +188,16 @@ class BOTAN_PUBLIC_API(3,0) Key_Constraints
 * X.509v2 CRL Reason Code.
 */
 enum class CRL_Code : uint32_t {
-   UNSPECIFIED            = 0,
-   KEY_COMPROMISE         = 1,
-   CA_COMPROMISE          = 2,
-   AFFILIATION_CHANGED    = 3,
-   SUPERSEDED             = 4,
-   CESSATION_OF_OPERATION = 5,
-   CERTIFICATE_HOLD       = 6,
-   REMOVE_FROM_CRL        = 8,
-   PRIVLEDGE_WITHDRAWN    = 9,
-   PRIVILEGE_WITHDRAWN    = 9,
-   AA_COMPROMISE          = 10,
-
-   DELETE_CRL_ENTRY       = 0xFF00,
-   OCSP_GOOD              = 0xFF01,
-   OCSP_UNKNOWN           = 0xFF02
+   Unspecified           = 0,
+   KeyCompromise         = 1,
+   CaCompromise          = 2,
+   AffiliationChanged    = 3,
+   Superseded            = 4,
+   CessationOfOperation  = 5,
+   CertificateHold       = 6,
+   RemoveFromCrl         = 8,
+   PrivilegeWithdrawn    = 9,
+   AaCompromise          = 10,
 };
 
 }
diff --git a/src/lib/x509/x509_crl.cpp b/src/lib/x509/x509_crl.cpp
index 3632940c2..7d3c440fe 100644
--- a/src/lib/x509/x509_crl.cpp
+++ b/src/lib/x509/x509_crl.cpp
@@ -100,7 +100,7 @@ bool X509_CRL::is_revoked(const X509_Certificate& cert) const
       {
       if(cert_serial == entry.serial_number())
          {
-         if(entry.reason_code() == CRL_Code::REMOVE_FROM_CRL)
+         if(entry.reason_code() == CRL_Code::RemoveFromCrl)
             is_revoked = false;
          else
             is_revoked = true;
diff --git a/src/lib/x509/x509_crl.h b/src/lib/x509/x509_crl.h
index c4435ef23..d550cea77 100644
--- a/src/lib/x509/x509_crl.h
+++ b/src/lib/x509/x509_crl.h
@@ -65,7 +65,7 @@ class BOTAN_PUBLIC_API(2,0) CRL_Entry final : public ASN1_Object
       * @param reason the reason code to set in the entry
       */
       CRL_Entry(const X509_Certificate& cert,
-                CRL_Code reason = CRL_Code::UNSPECIFIED);
+                CRL_Code reason = CRL_Code::Unspecified);
 
    private:
       friend class X509_CRL;
diff --git a/src/lib/x509/x509_ext.h b/src/lib/x509/x509_ext.h
index d1d5e9fa1..e7218e443 100644
--- a/src/lib/x509/x509_ext.h
+++ b/src/lib/x509/x509_ext.h
@@ -356,7 +356,7 @@ class BOTAN_PUBLIC_API(2,0) CRL_ReasonCode final : public Certificate_Extension
       std::unique_ptr<Certificate_Extension> copy() const override
          { return std::make_unique<CRL_ReasonCode>(m_reason); }
 
-      explicit CRL_ReasonCode(CRL_Code r = CRL_Code::UNSPECIFIED) : m_reason(r) {}
+      explicit CRL_ReasonCode(CRL_Code r = CRL_Code::Unspecified) : m_reason(r) {}
 
       CRL_Code get_reason() const { return m_reason; }
 
@@ -366,7 +366,7 @@ class BOTAN_PUBLIC_API(2,0) CRL_ReasonCode final : public Certificate_Extension
    private:
       std::string oid_name() const override { return "X509v3.ReasonCode"; }
 
-      bool should_encode() const override { return (m_reason != CRL_Code::UNSPECIFIED); }
+      bool should_encode() const override { return (m_reason != CRL_Code::Unspecified); }
       std::vector<uint8_t> encode_inner() const override;
       void decode_inner(const std::vector<uint8_t>&) override;
 


Test patch:
diff --git a/src/tests/test_certstor.cpp b/src/tests/test_certstor.cpp
index 7e6924017..955803473 100644
--- a/src/tests/test_certstor.cpp
+++ b/src/tests/test_certstor.cpp
@@ -135,9 +135,9 @@ Test::Result test_certstor_sqlite3_crl_test(const std::vector<CertificateAndKey>
          store.insert_cert(a.certificate);
          }
 
-      store.revoke_cert(certsandkeys[0].certificate, Botan::CRL_Code::CA_COMPROMISE);
-      store.revoke_cert(certsandkeys[3].certificate, Botan::CRL_Code::CA_COMPROMISE);
-      store.revoke_cert(certsandkeys[3].certificate, Botan::CRL_Code::CA_COMPROMISE);
+      store.revoke_cert(certsandkeys[0].certificate, Botan::CRL_Code::CaCompromise);
+      store.revoke_cert(certsandkeys[3].certificate, Botan::CRL_Code::CaCompromise);
+      store.revoke_cert(certsandkeys[3].certificate, Botan::CRL_Code::CaCompromise);
 
          {
          const auto crls = store.generate_crls();
diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp
index 63f13dfd0..db65a437b 100644
--- a/src/tests/unit_x509.cpp
+++ b/src/tests/unit_x509.cpp
@@ -959,7 +959,7 @@ Test::Result test_x509_cert(const Botan::Private_Key& ca_key,
    store.add_crl(crl1);
 
    std::vector<Botan::CRL_Entry> revoked;
-   revoked.push_back(Botan::CRL_Entry(user1_cert, Botan::CRL_Code::CESSATION_OF_OPERATION));
+   revoked.push_back(Botan::CRL_Entry(user1_cert, Botan::CRL_Code::CessationOfOperation));
    revoked.push_back(user2_cert);
 
    const Botan::X509_CRL crl2 = ca.update_crl(crl1, revoked, Test::rng());
@@ -976,7 +976,7 @@ Test::Result test_x509_cert(const Botan::Private_Key& ca_key,
    result.test_eq("user 1 revoked", result_u2.result_string(), revoked_str);
 
    revoked.clear();
-   revoked.push_back(Botan::CRL_Entry(user1_cert, Botan::CRL_Code::REMOVE_FROM_CRL));
+   revoked.push_back(Botan::CRL_Entry(user1_cert, Botan::CRL_Code::RemoveFromCrl));
    Botan::X509_CRL crl3 = ca.update_crl(crl2, revoked, Test::rng());
 
    store.add_crl(crl3);