diff options
Diffstat (limited to 'src/lib')
27 files changed, 84 insertions, 93 deletions
diff --git a/src/lib/asn1/alg_id.cpp b/src/lib/asn1/alg_id.cpp index b475865b5..4839303db 100644 --- a/src/lib/asn1/alg_id.cpp +++ b/src/lib/asn1/alg_id.cpp @@ -26,7 +26,7 @@ AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, */ AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, const std::vector<uint8_t>& param) : - AlgorithmIdentifier(OIDS::str2oid_or_throw(alg_id), param) + AlgorithmIdentifier(OID::from_string(alg_id), param) {} /* @@ -48,7 +48,7 @@ AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, */ AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, Encoding_Option option) : - oid(OIDS::str2oid_or_throw(alg_id)), + oid(OID::from_string(alg_id)), parameters() { const uint8_t DER_NULL[] = { 0x05, 0x00 }; diff --git a/src/lib/asn1/asn1_attribute.cpp b/src/lib/asn1/asn1_attribute.cpp index 1f07bbd4b..3106dda70 100644 --- a/src/lib/asn1/asn1_attribute.cpp +++ b/src/lib/asn1/asn1_attribute.cpp @@ -25,7 +25,7 @@ Attribute::Attribute(const OID& attr_oid, const std::vector<uint8_t>& attr_value */ Attribute::Attribute(const std::string& attr_oid, const std::vector<uint8_t>& attr_value) : - oid(OIDS::str2oid_or_throw(attr_oid)), + oid(OID::from_string(attr_oid)), parameters(attr_value) {} diff --git a/src/lib/asn1/asn1_oid.cpp b/src/lib/asn1/asn1_oid.cpp index dcb111644..bf3e2515b 100644 --- a/src/lib/asn1/asn1_oid.cpp +++ b/src/lib/asn1/asn1_oid.cpp @@ -12,6 +12,7 @@ #include <botan/parsing.h> #include <botan/oids.h> #include <algorithm> +#include <sstream> namespace Botan { @@ -93,14 +94,19 @@ OID::OID(const std::string& oid_str) */ std::string OID::to_string() const { - std::string oid_str; + std::ostringstream oss; for(size_t i = 0; i != m_id.size(); ++i) { - oid_str += std::to_string(m_id[i]); + oss << m_id[i]; if(i != m_id.size() - 1) - oid_str += "."; + oss << "."; } - return oid_str; + return oss.str(); + } + +std::string OID::to_formatted_string() const + { + return OIDS::oid2str_or_raw(*this); } /* diff --git a/src/lib/asn1/asn1_oid.h b/src/lib/asn1/asn1_oid.h index 387773784..5ce7a0c73 100644 --- a/src/lib/asn1/asn1_oid.h +++ b/src/lib/asn1/asn1_oid.h @@ -82,12 +82,18 @@ class BOTAN_PUBLIC_API(2,0) OID final : public ASN1_Object } /** - * Get this OID as a string + * Get this OID as a dotted-decimal string * @return string representing this OID */ std::string to_string() const; /** + * If there is a known name associated with this OID, return that. + * Otherwise return the result of to_string + */ + std::string to_formatted_string() const; + + /** * Compare two OIDs. * @return true if they are equal, false otherwise */ diff --git a/src/lib/kdf/prf_x942/prf_x942.cpp b/src/lib/kdf/prf_x942/prf_x942.cpp index 3fe0a682f..f4437b10b 100644 --- a/src/lib/kdf/prf_x942/prf_x942.cpp +++ b/src/lib/kdf/prf_x942/prf_x942.cpp @@ -7,7 +7,6 @@ #include <botan/prf_x942.h> #include <botan/der_enc.h> -#include <botan/oids.h> #include <botan/hash.h> #include <botan/loadstor.h> #include <algorithm> @@ -37,7 +36,6 @@ size_t X942_PRF::kdf(uint8_t key[], size_t key_len, const uint8_t label[], size_t label_len) const { std::unique_ptr<HashFunction> hash(HashFunction::create("SHA-160")); - const OID kek_algo(m_key_wrap_oid); secure_vector<uint8_t> h; secure_vector<uint8_t> in; @@ -56,7 +54,7 @@ size_t X942_PRF::kdf(uint8_t key[], size_t key_len, DER_Encoder().start_cons(SEQUENCE) .start_cons(SEQUENCE) - .encode(kek_algo) + .encode(m_key_wrap_oid) .raw_bytes(encode_x942_int(counter)) .end_cons() @@ -85,15 +83,9 @@ size_t X942_PRF::kdf(uint8_t key[], size_t key_len, return offset; } -/* -* X9.42 Constructor -*/ -X942_PRF::X942_PRF(const std::string& oid) +std::string X942_PRF::name() const { - if(OIDS::have_oid(oid)) - m_key_wrap_oid = OIDS::str2oid_or_empty(oid).to_string(); - else - m_key_wrap_oid = oid; + return "X9.42-PRF(" + m_key_wrap_oid.to_formatted_string() + ")"; } } diff --git a/src/lib/kdf/prf_x942/prf_x942.h b/src/lib/kdf/prf_x942/prf_x942.h index ebf9839f5..4b93d5966 100644 --- a/src/lib/kdf/prf_x942/prf_x942.h +++ b/src/lib/kdf/prf_x942/prf_x942.h @@ -9,6 +9,7 @@ #define BOTAN_ANSI_X942_PRF_H_ #include <botan/kdf.h> +#include <botan/asn1_oid.h> namespace Botan { @@ -18,7 +19,7 @@ namespace Botan { class BOTAN_PUBLIC_API(2,0) X942_PRF final : public KDF { public: - std::string name() const override { return "X9.42-PRF(" + m_key_wrap_oid + ")"; } + std::string name() const override; KDF* clone() const override { return new X942_PRF(m_key_wrap_oid); } @@ -27,9 +28,11 @@ class BOTAN_PUBLIC_API(2,0) X942_PRF final : public KDF const uint8_t salt[], size_t salt_len, const uint8_t label[], size_t label_len) const override; - explicit X942_PRF(const std::string& oid); + explicit X942_PRF(const std::string& oid) : m_key_wrap_oid(OID::from_string(oid)) {} + + explicit X942_PRF(const OID& oid) : m_key_wrap_oid(oid) {} private: - std::string m_key_wrap_oid; + OID m_key_wrap_oid; }; } diff --git a/src/lib/pk_pad/emsa1/emsa1.cpp b/src/lib/pk_pad/emsa1/emsa1.cpp index 295d23cd0..f7293db27 100644 --- a/src/lib/pk_pad/emsa1/emsa1.cpp +++ b/src/lib/pk_pad/emsa1/emsa1.cpp @@ -7,7 +7,6 @@ #include <botan/emsa1.h> #include <botan/exceptn.h> -#include <botan/oids.h> #include <botan/pk_keys.h> #include <botan/internal/padding.h> @@ -109,7 +108,7 @@ AlgorithmIdentifier EMSA1::config_for_x509(const Private_Key& key, " not supported for signature algorithm " + key.algo_name()); } - const OID oid = OIDS::str2oid_or_throw(key.algo_name() + "/" + name()); + const OID oid = OID::from_string(key.algo_name() + "/" + name()); const std::string algo_name = key.algo_name(); std::vector<uint8_t> parameters; diff --git a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp index e17858598..85556a39e 100644 --- a/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp +++ b/src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp @@ -8,7 +8,6 @@ #include <botan/emsa_pkcs1.h> #include <botan/hash_id.h> #include <botan/exceptn.h> -#include <botan/oids.h> #include <botan/pk_keys.h> #include <botan/internal/padding.h> @@ -99,7 +98,7 @@ AlgorithmIdentifier EMSA_PKCS1v15::config_for_x509(const Private_Key& key, // for RSA PKCSv1.5 parameters "SHALL" be NULL - const OID oid = OIDS::str2oid_or_throw(key.algo_name() + "/" + name()); + const OID oid = OID::from_string(key.algo_name() + "/" + name()); return AlgorithmIdentifier(oid, AlgorithmIdentifier::USE_NULL_PARAM); } diff --git a/src/lib/pk_pad/emsa_pssr/pssr.cpp b/src/lib/pk_pad/emsa_pssr/pssr.cpp index cc1aed814..652a7628b 100644 --- a/src/lib/pk_pad/emsa_pssr/pssr.cpp +++ b/src/lib/pk_pad/emsa_pssr/pssr.cpp @@ -10,7 +10,6 @@ #include <botan/rng.h> #include <botan/mgf1.h> #include <botan/internal/bit_ops.h> -#include <botan/oids.h> #include <botan/der_enc.h> #include <botan/pk_keys.h> #include <botan/internal/padding.h> diff --git a/src/lib/prov/openssl/openssl_ec.cpp b/src/lib/prov/openssl/openssl_ec.cpp index 53ed081a1..3f691f68a 100644 --- a/src/lib/prov/openssl/openssl_ec.cpp +++ b/src/lib/prov/openssl/openssl_ec.cpp @@ -10,7 +10,6 @@ #if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO) #include <botan/der_enc.h> #include <botan/pkcs8.h> - #include <botan/oids.h> #include <botan/internal/pk_ops_impl.h> #endif @@ -90,7 +89,7 @@ int OpenSSL_EC_nid_for(const OID& oid) if(oid.empty()) return -1; - const std::string name = OIDS::lookup(oid); + const std::string name = oid.to_formatted_string(); if(name == "secp192r1") return OpenSSL_EC_curve_builtin(NID_X9_62_prime192v1); diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index 95a56e473..41b48790f 100644 --- a/src/lib/pubkey/ec_group/ec_group.cpp +++ b/src/lib/pubkey/ec_group/ec_group.cpp @@ -13,7 +13,6 @@ #include <botan/internal/primality.h> #include <botan/ber_dec.h> #include <botan/der_enc.h> -#include <botan/oids.h> #include <botan/pem.h> #include <botan/reducer.h> #include <botan/mutex.h> @@ -361,11 +360,11 @@ EC_Group::EC_Group(const std::string& str) try { - OID oid = OIDS::str2oid_or_empty(str); + const OID oid = OID::from_string(str); if(oid.has_value()) m_data = ec_group_data().lookup(oid); } - catch(Invalid_OID&) + catch(...) { } diff --git a/src/lib/pubkey/pbes2/pbes2.cpp b/src/lib/pubkey/pbes2/pbes2.cpp index e9b471597..d68bf184b 100644 --- a/src/lib/pubkey/pbes2/pbes2.cpp +++ b/src/lib/pubkey/pbes2/pbes2.cpp @@ -34,7 +34,7 @@ SymmetricKey derive_key(const std::string& passphrase, const AlgorithmIdentifier& kdf_algo, size_t default_key_size) { - if(kdf_algo.get_oid() == OIDS::str2oid_or_throw("PKCS5.PBKDF2")) + if(kdf_algo.get_oid() == OID::from_string("PKCS5.PBKDF2")) { secure_vector<uint8_t> salt; size_t iterations = 0, key_length = 0; @@ -61,7 +61,7 @@ SymmetricKey derive_key(const std::string& passphrase, return pbkdf->pbkdf_iterations(key_length, passphrase, salt.data(), salt.size(), iterations); } #if defined(BOTAN_HAS_SCRYPT) - else if(kdf_algo.get_oid() == OIDS::str2oid_or_throw("Scrypt")) + else if(kdf_algo.get_oid() == OID::from_string("Scrypt")) { secure_vector<uint8_t> salt; size_t N = 0, r = 0, p = 0; @@ -142,7 +142,7 @@ secure_vector<uint8_t> derive_key(const std::string& passphrase, .encode(key_length) .end_cons(); - kdf_algo = AlgorithmIdentifier(OIDS::str2oid_or_throw("Scrypt"), scrypt_params); + kdf_algo = AlgorithmIdentifier(OID::from_string("Scrypt"), scrypt_params); return key; #else throw Not_Implemented("Scrypt is not available in this build"); @@ -251,7 +251,7 @@ pbes2_encrypt_shared(const secure_vector<uint8_t>& key_bits, ) .end_cons(); - AlgorithmIdentifier id(OIDS::str2oid_or_throw("PBE-PKCS5v20"), pbes2_params); + AlgorithmIdentifier id(OID::from_string("PBE-PKCS5v20"), pbes2_params); return std::make_pair(id, unlock(ctext)); } diff --git a/src/lib/pubkey/pk_algs.cpp b/src/lib/pubkey/pk_algs.cpp index 074149dac..fc8697585 100644 --- a/src/lib/pubkey/pk_algs.cpp +++ b/src/lib/pubkey/pk_algs.cpp @@ -6,7 +6,6 @@ */ #include <botan/pk_algs.h> -#include <botan/oids.h> #include <botan/parsing.h> #if defined(BOTAN_HAS_RSA) @@ -83,13 +82,8 @@ std::unique_ptr<Public_Key> load_public_key(const AlgorithmIdentifier& alg_id, const std::vector<uint8_t>& key_bits) { - const std::string oid_str = OIDS::oid2str_or_empty(alg_id.get_oid()); - - if(oid_str.empty()) - throw Decoding_Error("Unknown algorithm OID: " + alg_id.get_oid().to_string()); - + const std::string oid_str = alg_id.get_oid().to_formatted_string(); const std::vector<std::string> alg_info = split_on(oid_str, '/'); - const std::string alg_name = alg_info[0]; #if defined(BOTAN_HAS_RSA) @@ -162,16 +156,14 @@ load_public_key(const AlgorithmIdentifier& alg_id, return std::unique_ptr<Public_Key>(new XMSS_PublicKey(key_bits)); #endif - throw Decoding_Error("Unhandled PK algorithm " + alg_name); + throw Decoding_Error("Unknown or unavailable public key algorithm " + alg_name); } std::unique_ptr<Private_Key> load_private_key(const AlgorithmIdentifier& alg_id, const secure_vector<uint8_t>& key_bits) { - const std::string alg_name = OIDS::oid2str_or_empty(alg_id.get_oid()); - if(alg_name.empty()) - throw Decoding_Error("Unknown algorithm OID: " + alg_id.get_oid().to_string()); + const std::string alg_name = alg_id.get_oid().to_formatted_string(); #if defined(BOTAN_HAS_RSA) if(alg_name == "RSA") @@ -243,7 +235,7 @@ load_private_key(const AlgorithmIdentifier& alg_id, return std::unique_ptr<Private_Key>(new XMSS_PrivateKey(key_bits)); #endif - throw Decoding_Error("Unhandled PK algorithm " + alg_name); + throw Decoding_Error("Unknown or unavailable public key algorithm " + alg_name); } #if defined(BOTAN_HAS_ECC_GROUP) diff --git a/src/lib/tls/tls_callbacks.cpp b/src/lib/tls/tls_callbacks.cpp index 3e288690e..0dd758b75 100644 --- a/src/lib/tls/tls_callbacks.cpp +++ b/src/lib/tls/tls_callbacks.cpp @@ -13,7 +13,6 @@ #include <botan/ocsp.h> #include <botan/dh.h> #include <botan/ecdh.h> -#include <botan/oids.h> #include <botan/tls_exceptn.h> #include <botan/internal/ct_utils.h> @@ -177,7 +176,7 @@ std::pair<secure_vector<uint8_t>, std::vector<uint8_t>> TLS::Callbacks::tls_ecdh } else { - EC_Group group(OIDS::str2oid_or_throw(curve_name)); + EC_Group group(OID::from_string(curve_name)); ECDH_PublicKey peer_key(group, group.OS2ECP(peer_public_value)); policy.check_peer_key_acceptable(peer_key); ECDH_PrivateKey priv_key(rng, group); diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp index fa36b5283..197f4a11c 100644 --- a/src/lib/utils/parsing.cpp +++ b/src/lib/utils/parsing.cpp @@ -16,6 +16,10 @@ #include <limits> #include <set> +#if defined(BOTAN_HAS_ASN1) + #include <botan/asn1_oid.h> +#endif + namespace Botan { uint16_t to_uint16(const std::string& str) diff --git a/src/lib/utils/parsing.h b/src/lib/utils/parsing.h index 12cb3fa34..ed42ea8f5 100644 --- a/src/lib/utils/parsing.h +++ b/src/lib/utils/parsing.h @@ -95,7 +95,8 @@ std::string string_join(const std::vector<std::string>& strs, * @param oid the OID in string form * @return OID components */ -BOTAN_PUBLIC_API(2,0) std::vector<uint32_t> parse_asn1_oid(const std::string& oid); +BOTAN_PUBLIC_API(2,0) std::vector<uint32_t> +BOTAN_DEPRECATED("Use OID::from_string(oid).get_components()") parse_asn1_oid(const std::string& oid); /** * Compare two names using the X.509 comparison algorithm diff --git a/src/lib/x509/asn1_alt_name.cpp b/src/lib/x509/asn1_alt_name.cpp index 60e767543..1e5611c8b 100644 --- a/src/lib/x509/asn1_alt_name.cpp +++ b/src/lib/x509/asn1_alt_name.cpp @@ -75,7 +75,7 @@ std::multimap<std::string, std::string> AlternativeName::contents() const for(auto i = m_othernames.begin(); i != m_othernames.end(); ++i) { - multimap_insert(names, OIDS::oid2str_or_raw(i->first), i->second.value()); + multimap_insert(names, i->first.to_formatted_string(), i->second.value()); } return names; diff --git a/src/lib/x509/ocsp.cpp b/src/lib/x509/ocsp.cpp index b119c4490..34cb1d4fa 100644 --- a/src/lib/x509/ocsp.cpp +++ b/src/lib/x509/ocsp.cpp @@ -164,7 +164,7 @@ Certificate_Status_Code Response::verify_signature(const X509_Certificate& issue std::unique_ptr<Public_Key> pub_key(issuer.subject_public_key()); const std::vector<std::string> sig_info = - split_on(OIDS::oid2str_or_throw(m_sig_algo.get_oid()), '/'); + split_on(m_sig_algo.get_oid().to_formatted_string(), '/'); if(sig_info.size() != 2 || sig_info[0] != pub_key->algo_name()) return Certificate_Status_Code::OCSP_RESPONSE_INVALID; diff --git a/src/lib/x509/ocsp_types.cpp b/src/lib/x509/ocsp_types.cpp index 98c63a31b..9a0fbdf8d 100644 --- a/src/lib/x509/ocsp_types.cpp +++ b/src/lib/x509/ocsp_types.cpp @@ -10,7 +10,6 @@ #include <botan/ber_dec.h> #include <botan/x509_ext.h> #include <botan/hash.h> -#include <botan/oids.h> namespace Botan { @@ -39,8 +38,8 @@ bool CertID::is_id_for(const X509_Certificate& issuer, if(BigInt::decode(subject.serial_number()) != m_subject_serial) return false; - const std::string hash_algo = OIDS::oid2str_or_throw(m_hash_id.get_oid()); - std::unique_ptr<HashFunction> hash = HashFunction::create(hash_algo); + const std::string hash_algo = m_hash_id.get_oid().to_formatted_string(); + std::unique_ptr<HashFunction> hash = HashFunction::create_or_throw(hash_algo); if(m_issuer_dn_hash != unlock(hash->process(subject.raw_issuer_dn()))) return false; diff --git a/src/lib/x509/pkcs10.cpp b/src/lib/x509/pkcs10.cpp index 1270e4159..5e40cb4c3 100644 --- a/src/lib/x509/pkcs10.cpp +++ b/src/lib/x509/pkcs10.cpp @@ -148,19 +148,19 @@ std::unique_ptr<PKCS10_Data> decode_pkcs10(const std::vector<uint8_t>& body) const OID& oid = attr.get_oid(); BER_Decoder value(attr.get_parameters()); - if(oid == OIDS::str2oid_or_throw("PKCS9.EmailAddress")) + if(oid == OID::from_string("PKCS9.EmailAddress")) { ASN1_String email; value.decode(email); pkcs9_email.insert(email.value()); } - else if(oid == OIDS::str2oid_or_throw("PKCS9.ChallengePassword")) + else if(oid == OID::from_string("PKCS9.ChallengePassword")) { ASN1_String challenge_password; value.decode(challenge_password); data->m_challenge = challenge_password.value(); } - else if(oid == OIDS::str2oid_or_throw("PKCS9.ExtensionRequest")) + else if(oid == OID::from_string("PKCS9.ExtensionRequest")) { value.decode(data->m_extensions).verify_end(); } @@ -260,7 +260,7 @@ const Extensions& PKCS10_Request::extensions() const */ Key_Constraints PKCS10_Request::constraints() const { - if(auto ext = extensions().get(OIDS::str2oid_or_throw("X509v3.KeyUsage"))) + if(auto ext = extensions().get(OID::from_string("X509v3.KeyUsage"))) { return dynamic_cast<Cert_Extension::Key_Usage&>(*ext).get_constraints(); } @@ -273,7 +273,7 @@ Key_Constraints PKCS10_Request::constraints() const */ std::vector<OID> PKCS10_Request::ex_constraints() const { - if(auto ext = extensions().get(OIDS::str2oid_or_throw("X509v3.ExtendedKeyUsage"))) + if(auto ext = extensions().get(OID::from_string("X509v3.ExtendedKeyUsage"))) { return dynamic_cast<Cert_Extension::Extended_Key_Usage&>(*ext).get_oids(); } @@ -286,7 +286,7 @@ std::vector<OID> PKCS10_Request::ex_constraints() const */ bool PKCS10_Request::is_CA() const { - if(auto ext = extensions().get(OIDS::str2oid_or_throw("X509v3.BasicConstraints"))) + if(auto ext = extensions().get(OID::from_string("X509v3.BasicConstraints"))) { return dynamic_cast<Cert_Extension::Basic_Constraints&>(*ext).get_is_ca(); } @@ -299,7 +299,7 @@ bool PKCS10_Request::is_CA() const */ size_t PKCS10_Request::path_limit() const { - if(auto ext = extensions().get(OIDS::str2oid_or_throw("X509v3.BasicConstraints"))) + if(auto ext = extensions().get(OID::from_string("X509v3.BasicConstraints"))) { Cert_Extension::Basic_Constraints& basic_constraints = dynamic_cast<Cert_Extension::Basic_Constraints&>(*ext); if(basic_constraints.get_is_ca()) diff --git a/src/lib/x509/x509_dn.cpp b/src/lib/x509/x509_dn.cpp index edb9b7d0b..bd8b60c40 100644 --- a/src/lib/x509/x509_dn.cpp +++ b/src/lib/x509/x509_dn.cpp @@ -23,7 +23,7 @@ namespace Botan { void X509_DN::add_attribute(const std::string& type, const std::string& str) { - add_attribute(OIDS::str2oid_or_throw(type), str); + add_attribute(OID::from_string(type), str); } /* @@ -59,8 +59,7 @@ std::multimap<std::string, std::string> X509_DN::contents() const for(auto& i : m_rdn) { - const std::string str_value = OIDS::oid2str_or_raw(i.first); - multimap_insert(retval, str_value, i.second.value()); + multimap_insert(retval, i.first.to_formatted_string(), i.second.value()); } return retval; } @@ -87,7 +86,7 @@ bool X509_DN::has_field(const OID& oid) const std::string X509_DN::get_first_attribute(const std::string& attr) const { - const OID oid = OIDS::str2oid_or_throw(deref_info_field(attr)); + const OID oid = OID::from_string(deref_info_field(attr)); return get_first_attribute(oid).value(); } @@ -109,7 +108,7 @@ ASN1_String X509_DN::get_first_attribute(const OID& oid) const */ std::vector<std::string> X509_DN::get_attribute(const std::string& attr) const { - const OID oid = OIDS::str2oid_or_throw(deref_info_field(attr)); + const OID oid = OID::from_string(deref_info_field(attr)); std::vector<std::string> values; @@ -305,7 +304,7 @@ namespace { std::string to_short_form(const OID& oid) { - const std::string long_id = OIDS::oid2str_or_raw(oid); + const std::string long_id = oid.to_formatted_string(); if(long_id == "X520.CommonName") return "CN"; diff --git a/src/lib/x509/x509_ext.cpp b/src/lib/x509/x509_ext.cpp index cfcc7da59..0bfc337c4 100644 --- a/src/lib/x509/x509_ext.cpp +++ b/src/lib/x509/x509_ext.cpp @@ -12,7 +12,6 @@ #include <botan/datastor.h> #include <botan/der_enc.h> #include <botan/ber_dec.h> -#include <botan/oids.h> #include <botan/hash.h> #include <botan/internal/bit_ops.h> #include <algorithm> @@ -786,7 +785,7 @@ std::vector<uint8_t> Authority_Information_Access::encode_inner() const DER_Encoder(output) .start_cons(SEQUENCE) .start_cons(SEQUENCE) - .encode(OIDS::str2oid_or_throw("PKIX.OCSP")) + .encode(OID::from_string("PKIX.OCSP")) .add_object(ASN1_Tag(6), CONTEXT_SPECIFIC, url.value()) .end_cons() .end_cons(); @@ -805,7 +804,7 @@ void Authority_Information_Access::decode_inner(const std::vector<uint8_t>& in) info.decode(oid); - if(oid == OIDS::str2oid_or_throw("PKIX.OCSP")) + if(oid == OID::from_string("PKIX.OCSP")) { BER_Object name = info.get_next_object(); @@ -815,7 +814,7 @@ void Authority_Information_Access::decode_inner(const std::vector<uint8_t>& in) } } - if(oid == OIDS::str2oid_or_throw("PKIX.CertificateAuthorityIssuers")) + if(oid == OID::from_string("PKIX.CertificateAuthorityIssuers")) { BER_Object name = info.get_next_object(); diff --git a/src/lib/x509/x509_ext.h b/src/lib/x509/x509_ext.h index e8b21ef9b..2f818af63 100644 --- a/src/lib/x509/x509_ext.h +++ b/src/lib/x509/x509_ext.h @@ -36,7 +36,7 @@ class BOTAN_PUBLIC_API(2,0) Certificate_Extension /* * @return specific OID name * If possible OIDS table should match oid_name to OIDS, ie - * OIDS::lookup(ext->oid_name()) == ext->oid_of() + * OID::from_string(ext->oid_name()) == ext->oid_of() * Should return empty string if OID is not known */ virtual std::string oid_name() const = 0; diff --git a/src/lib/x509/x509_obj.cpp b/src/lib/x509/x509_obj.cpp index 795a1d119..e6767ea98 100644 --- a/src/lib/x509/x509_obj.cpp +++ b/src/lib/x509/x509_obj.cpp @@ -7,7 +7,6 @@ #include <botan/x509_obj.h> #include <botan/pubkey.h> -#include <botan/oids.h> #include <botan/der_enc.h> #include <botan/ber_dec.h> #include <botan/parsing.h> @@ -139,7 +138,7 @@ std::vector<uint8_t> X509_Object::tbs_data() const std::string X509_Object::hash_used_for_signature() const { const OID& oid = m_sig_algo.get_oid(); - const std::vector<std::string> sig_info = split_on(OIDS::oid2str_or_throw(oid), '/'); + const std::vector<std::string> sig_info = split_on(oid.to_formatted_string(), '/'); if(sig_info.size() == 1 && sig_info[0] == "Ed25519") return "SHA-512"; @@ -148,7 +147,8 @@ std::string X509_Object::hash_used_for_signature() const if(sig_info[1] == "EMSA4") { - return OIDS::oid2str_or_throw(decode_pss_params(signature_algorithm().get_parameters()).hash_algo.get_oid()); + const OID hash_oid = decode_pss_params(signature_algorithm().get_parameters()).hash_algo.get_oid(); + return hash_oid.to_formatted_string(); } else { @@ -184,7 +184,7 @@ bool X509_Object::check_signature(const Public_Key& pub_key) const Certificate_Status_Code X509_Object::verify_signature(const Public_Key& pub_key) const { const std::vector<std::string> sig_info = - split_on(OIDS::oid2str_or_throw(m_sig_algo.get_oid()), '/'); + split_on(m_sig_algo.get_oid().to_formatted_string(), '/'); if(sig_info.size() < 1 || sig_info.size() > 2 || sig_info[0] != pub_key.algo_name()) return Certificate_Status_Code::SIGNATURE_ALGO_BAD_PARAMS; @@ -210,7 +210,7 @@ Certificate_Status_Code X509_Object::verify_signature(const Public_Key& pub_key) Pss_params pss_parameter = decode_pss_params(signature_algorithm().get_parameters()); // hash_algo must be SHA1, SHA2-224, SHA2-256, SHA2-384 or SHA2-512 - const std::string hash_algo = OIDS::oid2str_or_throw(pss_parameter.hash_algo.get_oid()); + const std::string hash_algo = pss_parameter.hash_algo.get_oid().to_formatted_string(); if(hash_algo != "SHA-160" && hash_algo != "SHA-224" && hash_algo != "SHA-256" && @@ -220,7 +220,7 @@ Certificate_Status_Code X509_Object::verify_signature(const Public_Key& pub_key) return Certificate_Status_Code::UNTRUSTED_HASH; } - const std::string mgf_algo = OIDS::oid2str_or_throw(pss_parameter.mask_gen_algo.get_oid()); + const std::string mgf_algo = pss_parameter.mask_gen_algo.get_oid().to_formatted_string(); if(mgf_algo != "MGF1") { return Certificate_Status_Code::SIGNATURE_ALGO_BAD_PARAMS; @@ -353,7 +353,7 @@ std::string choose_sig_algo(AlgorithmIdentifier& sig_algo, } else { - sig_algo = AlgorithmIdentifier(OIDS::str2oid_or_throw("Ed25519"), AlgorithmIdentifier::USE_EMPTY_PARAM); + sig_algo = AlgorithmIdentifier(OID::from_string("Ed25519"), AlgorithmIdentifier::USE_EMPTY_PARAM); return "Pure"; } } diff --git a/src/lib/x509/x509cert.cpp b/src/lib/x509/x509cert.cpp index 890360c8a..b21a8b5a9 100644 --- a/src/lib/x509/x509cert.cpp +++ b/src/lib/x509/x509cert.cpp @@ -500,7 +500,7 @@ bool X509_Certificate::allowed_usage(Key_Constraints usage) const bool X509_Certificate::allowed_extended_usage(const std::string& usage) const { - return allowed_extended_usage(OIDS::str2oid_or_throw(usage)); + return allowed_extended_usage(OID::from_string(usage)); } bool X509_Certificate::allowed_extended_usage(const OID& usage) const @@ -552,7 +552,7 @@ bool X509_Certificate::has_constraints(Key_Constraints constraints) const bool X509_Certificate::has_ex_constraint(const std::string& ex_constraint) const { - return has_ex_constraint(OIDS::str2oid_or_throw(ex_constraint)); + return has_ex_constraint(OID::from_string(ex_constraint)); } bool X509_Certificate::has_ex_constraint(const OID& usage) const @@ -566,7 +566,7 @@ bool X509_Certificate::has_ex_constraint(const OID& usage) const */ bool X509_Certificate::is_critical(const std::string& ex_name) const { - return v3_extensions().critical_extension_set(OIDS::str2oid_or_throw(ex_name)); + return v3_extensions().critical_extension_set(OID::from_string(ex_name)); } std::string X509_Certificate::ocsp_responder() const @@ -695,7 +695,7 @@ std::vector<std::string> lookup_oids(const std::vector<OID>& oids) for(const OID& oid : oids) { - out.push_back(OIDS::oid2str_or_raw(oid)); + out.push_back(oid.to_formatted_string()); } return out; } @@ -823,8 +823,7 @@ std::string X509_Certificate::to_string() const out << "Extended Constraints:\n"; for(auto&& oid : ex_constraints) { - const std::string oid_str = OIDS::oid2str_or_raw(oid); - out << " " << oid.to_string() << "\n"; + out << " " << oid.to_formatted_string() << "\n"; } } @@ -869,8 +868,7 @@ std::string X509_Certificate::to_string() const if(!crl_distribution_point().empty()) out << "CRL " << crl_distribution_point() << "\n"; - out << "Signature algorithm: " << - OIDS::oid2str_or_raw(this->signature_algorithm().get_oid()) << "\n"; + out << "Signature algorithm: " << this->signature_algorithm().get_oid().to_formatted_string() << "\n"; out << "Serial number: " << hex_encode(this->serial_number()) << "\n"; diff --git a/src/lib/x509/x509opt.cpp b/src/lib/x509/x509opt.cpp index 723d57742..f762acd7b 100644 --- a/src/lib/x509/x509opt.cpp +++ b/src/lib/x509/x509opt.cpp @@ -6,7 +6,6 @@ */ #include <botan/x509self.h> -#include <botan/oids.h> #include <botan/parsing.h> #include <chrono> @@ -49,7 +48,7 @@ void X509_Cert_Options::add_ex_constraint(const OID& oid) */ void X509_Cert_Options::add_ex_constraint(const std::string& oid_str) { - ex_constraints.push_back(OIDS::str2oid_or_throw(oid_str)); + ex_constraints.push_back(OID::from_string(oid_str)); } /* diff --git a/src/lib/x509/x509self.cpp b/src/lib/x509/x509self.cpp index d848185ec..dd4ed7e3f 100644 --- a/src/lib/x509/x509self.cpp +++ b/src/lib/x509/x509self.cpp @@ -10,7 +10,6 @@ #include <botan/x509_ca.h> #include <botan/der_enc.h> #include <botan/pubkey.h> -#include <botan/oids.h> #include <botan/hash.h> namespace Botan { @@ -35,7 +34,7 @@ void load_info(const X509_Cert_Options& opts, X509_DN& subject_dn, subject_dn.add_attribute("X520.SerialNumber", opts.serial_number); subject_alt = AlternativeName(opts.email, opts.uri, opts.dns, opts.ip); - subject_alt.add_othername(OIDS::str2oid_or_throw("PKIX.XMPPAddr"), + subject_alt.add_othername(OID::from_string("PKIX.XMPPAddr"), opts.xmpp, UTF8_STRING); for(auto dns : opts.more_dns) |