diff options
author | Jack Lloyd <[email protected]> | 2019-08-04 08:26:06 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-08-04 16:26:50 -0400 |
commit | 0006bd1db9a96c294f2da852218d3f8579f422a9 (patch) | |
tree | 15600a4e8369eb167be052e8343c58dcb6693a3a /src/lib/pubkey | |
parent | 247df8cae3fbec8d9b608c5dc8b42a4f6bdeef8b (diff) |
Reduce usage of oids.h with the addition of some helpers on OID
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r-- | src/lib/pubkey/ec_group/ec_group.cpp | 5 | ||||
-rw-r--r-- | src/lib/pubkey/pbes2/pbes2.cpp | 8 | ||||
-rw-r--r-- | src/lib/pubkey/pk_algs.cpp | 16 |
3 files changed, 10 insertions, 19 deletions
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) |