diff options
Diffstat (limited to 'src/libstate')
-rw-r--r-- | src/libstate/get_enc.cpp | 123 |
1 files changed, 41 insertions, 82 deletions
diff --git a/src/libstate/get_enc.cpp b/src/libstate/get_enc.cpp index b3bfe5273..f93ecb703 100644 --- a/src/libstate/get_enc.cpp +++ b/src/libstate/get_enc.cpp @@ -5,8 +5,7 @@ #include <botan/lookup.h> #include <botan/libstate.h> -#include <botan/parsing.h> -#include <botan/util.h> +#include <botan/scan_name.h> #if defined(BOTAN_HAS_MGF1) #include <botan/mgf1.h> @@ -71,60 +70,46 @@ namespace Botan { *************************************************/ EMSA* get_emsa(const std::string& algo_spec) { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - const std::string emsa_name = global_state().deref_alias(name[0]); + SCAN_Name request(algo_spec); #if defined(BOTAN_HAS_EMSA_RAW) - if(emsa_name == "Raw") - { - if(name.size() == 1) - return new EMSA_Raw; - } + if(request.algo_name() == "Raw" && request.arg_count() == 0) + return new EMSA_Raw; #endif #if defined(BOTAN_HAS_EMSA1) - if(emsa_name == "EMSA1") - { - if(name.size() == 2) - return new EMSA1(get_hash(name[1])); - } + if(request.algo_name() == "EMSA1" && request.arg_count() == 1) + return new EMSA1(get_hash(request.argument(0))); #endif #if defined(BOTAN_HAS_EMSA1_BSI) - if(emsa_name == "EMSA1_BSI") - { - if(name.size() == 2) - return new EMSA1_BSI(get_hash(name[1])); - } + if(request.algo_name() == "EMSA1_BSI" && request.arg_count() == 1) + return new EMSA1_BSI(get_hash(request.argument(0))); #endif #if defined(BOTAN_HAS_EMSA2) - if(emsa_name == "EMSA2") - { - if(name.size() == 2) - return new EMSA2(get_hash(name[1])); - } + if(request.algo_name() == "EMSA2" && request.arg_count() == 1) + return new EMSA2(get_hash(request.argument(0))); #endif #if defined(BOTAN_HAS_EMSA3) - if(emsa_name == "EMSA3") - { - if(name.size() == 2) - return new EMSA3(get_hash(name[1])); - } + if(request.algo_name() == "EMSA3" && request.arg_count() == 1) + return new EMSA3(get_hash(request.argument(0))); #endif #if defined(BOTAN_HAS_EMSA4) - if(emsa_name == "EMSA4") + if(request.algo_name() == "EMSA4" && request.arg_count_between(1, 3)) { - // EMSA4 is hardcoded to use MGF1 - if(name.size() >= 3 && name[2] != "MGF1") - throw Algorithm_Not_Found(algo_spec); - - if(name.size() == 2 || name.size() == 3) - return new EMSA4(get_hash(name[1])); - else if(name.size() == 4) - return new EMSA4(get_hash(name[1]), to_u32bit(name[3])); + // 3 args: Hash, MGF, salt size (MGF is hardcoded MGF1 in Botan) + if(request.arg_count() == 1) + return new EMSA4(get_hash(request.argument(0))); + + if(request.arg_count() == 2 && request.argument(1) != "MGF1") + return new EMSA4(get_hash(request.argument(0))); + + if(request.arg_count() == 3) + return new EMSA4(get_hash(request.argument(0)), + request.argument_as_u32bit(2, 0)); } #endif @@ -136,30 +121,20 @@ EMSA* get_emsa(const std::string& algo_spec) *************************************************/ EME* get_eme(const std::string& algo_spec) { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - const std::string eme_name = global_state().deref_alias(name[0]); + SCAN_Name request(algo_spec); #if defined(BOTAN_HAS_EME_PKCS1v15) - if(eme_name == "PKCS1v15") - { - if(name.size() == 1) - return new EME_PKCS1v15; - } + if(request.algo_name() == "PKCS1v15" && request.arg_count() == 0) + return new EME_PKCS1v15; #endif #if defined(BOTAN_HAS_EME1) - if(eme_name == "EME1") + if(request.algo_name() == "EME1" && request.arg_count_between(1, 2)) { - if(name.size() >= 2) + if(request.arg_count() == 1 || + (request.arg_count() == 2 && request.argument(1) == "MGF1")) { - if(name.size() >= 3) - { - // EME1 is hardcoded for MGF1 - if(name[2] != "MGF1") - throw Algorithm_Not_Found(algo_spec); - } - - return new EME1(get_hash(name[1])); + return new EME1(get_hash(request.argument(0))); } } #endif @@ -172,47 +147,31 @@ EME* get_eme(const std::string& algo_spec) *************************************************/ KDF* get_kdf(const std::string& algo_spec) { - std::vector<std::string> name = parse_algorithm_name(algo_spec); - const std::string kdf_name = global_state().deref_alias(name[0]); + SCAN_Name request(algo_spec); #if defined(BOTAN_HAS_KDF1) - if(kdf_name == "KDF1") - { - if(name.size() == 2) - return new KDF1(get_hash(name[1])); - } + if(request.algo_name() == "KDF1" && request.arg_count() == 1) + return new KDF1(get_hash(request.argument(0))); #endif #if defined(BOTAN_HAS_KDF2) - if(kdf_name == "KDF2") - { - if(name.size() == 2) - return new KDF2(get_hash(name[1])); - } + if(request.algo_name() == "KDF2" && request.arg_count() == 1) + return new KDF2(get_hash(request.argument(0))); #endif #if defined(BOTAN_HAS_X942_PRF) - if(kdf_name == "X9.42-PRF") - { - if(name.size() == 2) - return new X942_PRF(name[1]); - } + if(request.algo_name() == "X9.42-PRF" && request.arg_count() == 1) + return new X942_PRF(request.argument(0)); #endif #if defined(BOTAN_HAS_TLS_V10_PRF) - if(kdf_name == "TLS-PRF") - { - if(name.size() == 1) - return new TLS_PRF; - } + if(request.algo_name() == "TLS-PRF" && request.arg_count() == 0) + return new TLS_PRF; #endif #if defined(BOTAN_HAS_SSL_V3_PRF) - if(kdf_name == "SSL3-PRF") - { - if(name.size() == 1) - return new SSL3_PRF; - } + if(request.algo_name() == "SSL3-PRF" && request.arg_count() == 0) + return new SSL3_PRF; #endif throw Algorithm_Not_Found(algo_spec); |