diff options
Diffstat (limited to 'src/lib/base')
-rw-r--r-- | src/lib/base/info.txt | 1 | ||||
-rw-r--r-- | src/lib/base/scan_name.cpp | 154 | ||||
-rw-r--r-- | src/lib/base/scan_name.h | 125 |
3 files changed, 0 insertions, 280 deletions
diff --git a/src/lib/base/info.txt b/src/lib/base/info.txt index 3bb3d9501..f8da0cf50 100644 --- a/src/lib/base/info.txt +++ b/src/lib/base/info.txt @@ -1,7 +1,6 @@ <header:public> buf_comp.h secmem.h -scan_name.h sym_algo.h symkey.h </header:public> diff --git a/src/lib/base/scan_name.cpp b/src/lib/base/scan_name.cpp deleted file mode 100644 index 4ea2f3dcd..000000000 --- a/src/lib/base/scan_name.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* -* SCAN Name Abstraction -* (C) 2008-2009,2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/scan_name.h> -#include <botan/internal/parsing.h> -#include <botan/exceptn.h> - -namespace Botan { - -namespace { - -std::string make_arg(const std::vector<std::pair<size_t, std::string>>& name, size_t start) - { - std::string output = name[start].second; - size_t level = name[start].first; - - size_t paren_depth = 0; - - for(size_t i = start + 1; i != name.size(); ++i) - { - if(name[i].first <= name[start].first) - break; - - if(name[i].first > level) - { - output += "(" + name[i].second; - ++paren_depth; - } - else if(name[i].first < level) - { - for (size_t j = name[i].first; j < level; j++) { - output += ")"; - --paren_depth; - } - output += "," + name[i].second; - } - else - { - if(output[output.size() - 1] != '(') - output += ","; - output += name[i].second; - } - - level = name[i].first; - } - - for(size_t i = 0; i != paren_depth; ++i) - output += ")"; - - return output; - } - -} - -SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec)) - { - } - -SCAN_Name::SCAN_Name(std::string algo_spec) : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info() - { - if(algo_spec.size() == 0) - throw Invalid_Argument("Expected algorithm name, got empty string"); - - std::vector<std::pair<size_t, std::string>> name; - size_t level = 0; - std::pair<size_t, std::string> accum = std::make_pair(level, ""); - - const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': "; - - for(size_t i = 0; i != algo_spec.size(); ++i) - { - char c = algo_spec[i]; - - if(c == '/' || c == ',' || c == '(' || c == ')') - { - if(c == '(') - ++level; - else if(c == ')') - { - if(level == 0) - throw Decoding_Error(decoding_error + "Mismatched parens"); - --level; - } - - if(c == '/' && level > 0) - accum.second.push_back(c); - else - { - if(accum.second != "") - name.push_back(accum); - accum = std::make_pair(level, ""); - } - } - else - accum.second.push_back(c); - } - - if(accum.second != "") - name.push_back(accum); - - if(level != 0) - throw Decoding_Error(decoding_error + "Missing close paren"); - - if(name.size() == 0) - throw Decoding_Error(decoding_error + "Empty name"); - - m_alg_name = name[0].second; - - bool in_modes = false; - - for(size_t i = 1; i != name.size(); ++i) - { - if(name[i].first == 0) - { - m_mode_info.push_back(make_arg(name, i)); - in_modes = true; - } - else if(name[i].first == 1 && !in_modes) - m_args.push_back(make_arg(name, i)); - } - } - -std::string SCAN_Name::arg(size_t i) const - { - if(i >= arg_count()) - throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) + - " out of range for '" + to_string() + "'"); - return m_args[i]; - } - -std::string SCAN_Name::arg(size_t i, const std::string& def_value) const - { - if(i >= arg_count()) - return def_value; - return m_args[i]; - } - -size_t SCAN_Name::arg_as_integer(size_t i, size_t def_value) const - { - if(i >= arg_count()) - return def_value; - return to_u32bit(m_args[i]); - } - -size_t SCAN_Name::arg_as_integer(size_t i) const - { - return to_u32bit(arg(i)); - } - -} diff --git a/src/lib/base/scan_name.h b/src/lib/base/scan_name.h deleted file mode 100644 index c4b2a034f..000000000 --- a/src/lib/base/scan_name.h +++ /dev/null @@ -1,125 +0,0 @@ -/* -* SCAN Name Abstraction -* (C) 2008,2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_SCAN_NAME_H_ -#define BOTAN_SCAN_NAME_H_ - -#include <botan/types.h> -#include <string> -#include <vector> - -BOTAN_FUTURE_INTERNAL_HEADER(scan_name.h) - -namespace Botan { - -/** -A class encapsulating a SCAN name (similar to JCE conventions) -http://www.users.zetnet.co.uk/hopwood/crypto/scan/ -*/ -class BOTAN_PUBLIC_API(2,0) SCAN_Name final - { - public: - /** - * Create a SCAN_Name - * @param algo_spec A SCAN-format name - */ - explicit SCAN_Name(const char* algo_spec); - - /** - * Create a SCAN_Name - * @param algo_spec A SCAN-format name - */ - explicit SCAN_Name(std::string algo_spec); - - /** - * @return original input string - */ - const std::string& to_string() const { return m_orig_algo_spec; } - - /** - * @return algorithm name - */ - const std::string& algo_name() const { return m_alg_name; } - - /** - * @return number of arguments - */ - size_t arg_count() const { return m_args.size(); } - - /** - * @param lower is the lower bound - * @param upper is the upper bound - * @return if the number of arguments is between lower and upper - */ - bool arg_count_between(size_t lower, size_t upper) const - { return ((arg_count() >= lower) && (arg_count() <= upper)); } - - /** - * @param i which argument - * @return ith argument - */ - std::string arg(size_t i) const; - - /** - * @param i which argument - * @param def_value the default value - * @return ith argument or the default value - */ - std::string arg(size_t i, const std::string& def_value) const; - - /** - * @param i which argument - * @param def_value the default value - * @return ith argument as an integer, or the default value - */ - size_t arg_as_integer(size_t i, size_t def_value) const; - - /** - * @param i which argument - * @return ith argument as an integer - */ - size_t arg_as_integer(size_t i) const; - - /** - * @return cipher mode (if any) - */ - std::string cipher_mode() const - { return (m_mode_info.size() >= 1) ? m_mode_info[0] : ""; } - - /** - * @return cipher mode padding (if any) - */ - std::string cipher_mode_pad() const - { return (m_mode_info.size() >= 2) ? m_mode_info[1] : ""; } - - private: - std::string m_orig_algo_spec; - std::string m_alg_name; - std::vector<std::string> m_args; - std::vector<std::string> m_mode_info; - }; - -// This is unrelated but it is convenient to stash it here -template<typename T> -std::vector<std::string> probe_providers_of(const std::string& algo_spec, - const std::vector<std::string>& possible) - { - std::vector<std::string> providers; - for(auto&& prov : possible) - { - std::unique_ptr<T> o(T::create(algo_spec, prov)); - if(o) - { - providers.push_back(prov); // available - } - } - return providers; - } - -} - -#endif |