Botan
1.11.15
|
#include <scan_name.h>
Public Member Functions | |
const std::string & | algo_name () const |
std::string | algo_name_and_args () const |
std::string | all_arguments () const |
std::string | arg (size_t i) const |
std::string | arg (size_t i, const std::string &def_value) const |
size_t | arg_as_integer (size_t i, size_t def_value) const |
size_t | arg_count () const |
bool | arg_count_between (size_t lower, size_t upper) const |
const std::string & | as_string () const |
std::string | cipher_mode () const |
std::string | cipher_mode_pad () const |
SCAN_Name (const char *algo_spec) | |
SCAN_Name (std::string algo_spec) | |
SCAN_Name (std::string algo_spec, const std::string &extra) | |
Static Public Member Functions | |
static void | add_alias (const std::string &alias, const std::string &basename) |
static std::string | deref_alias (const std::string &alias) |
A class encapsulating a SCAN name (similar to JCE conventions) http://www.users.zetnet.co.uk/hopwood/crypto/scan/
Definition at line 23 of file scan_name.h.
Botan::SCAN_Name::SCAN_Name | ( | const char * | algo_spec | ) |
algo_spec | A SCAN-format name |
Definition at line 70 of file scan_name.cpp.
: SCAN_Name(std::string(algo_spec)) { }
Botan::SCAN_Name::SCAN_Name | ( | std::string | algo_spec | ) |
algo_spec | A SCAN-format name |
Definition at line 74 of file scan_name.cpp.
References c, and deref_alias().
{ orig_algo_spec = algo_spec; 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 + "': "; algo_spec = SCAN_Name::deref_alias(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(deref_aliases(accum)); accum = std::make_pair(level, ""); } } else accum.second.push_back(c); } if(accum.second != "") name.push_back(deref_aliases(accum)); if(level != 0) throw Decoding_Error(decoding_error + "Missing close paren"); if(name.size() == 0) throw Decoding_Error(decoding_error + "Empty name"); alg_name = name[0].second; bool in_modes = false; for(size_t i = 1; i != name.size(); ++i) { if(name[i].first == 0) { mode_info.push_back(make_arg(name, i)); in_modes = true; } else if(name[i].first == 1 && !in_modes) args.push_back(make_arg(name, i)); } }
Botan::SCAN_Name::SCAN_Name | ( | std::string | algo_spec, |
const std::string & | extra | ||
) |
algo_spec | A SCAN-format name |
Definition at line 65 of file scan_name.cpp.
: SCAN_Name(algo_spec) { alg_name += extra; }
void Botan::SCAN_Name::add_alias | ( | const std::string & | alias, |
const std::string & | basename | ||
) | [static] |
Definition at line 201 of file scan_name.cpp.
{
std::lock_guard<std::mutex> lock(g_alias_map_mutex);
if(g_alias_map.find(alias) == g_alias_map.end())
g_alias_map[alias] = basename;
}
const std::string& Botan::SCAN_Name::algo_name | ( | ) | const [inline] |
Definition at line 49 of file scan_name.h.
Referenced by Botan::get_eme(), Botan::get_kdf(), Botan::OAEP::make(), Botan::RC4::make(), Botan::CTR_BE::make(), and Botan::OFB::make().
{ return alg_name; }
std::string Botan::SCAN_Name::algo_name_and_args | ( | ) | const [inline] |
Definition at line 54 of file scan_name.h.
{ return algo_name() + all_arguments(); }
std::string Botan::SCAN_Name::all_arguments | ( | ) | const |
Definition at line 139 of file scan_name.cpp.
References arg(), and arg_count().
std::string Botan::SCAN_Name::arg | ( | size_t | i | ) | const |
i | which argument |
Definition at line 156 of file scan_name.cpp.
References arg_count(), as_string(), and Botan::ASN1::to_string().
Referenced by all_arguments(), Botan::hash_for_deterministic_signature(), Botan::OAEP::make(), Botan::HKDF::make(), Botan::Parallel::make(), Botan::PSSR::make(), Botan::Skein_512::make(), Botan::Comb4P::make(), Botan::Cascade_Cipher::make(), Botan::CBC_MAC::make(), Botan::HMAC::make(), Botan::CTR_BE::make(), Botan::OFB::make(), Botan::CMAC::make(), Botan::TLS_12_PRF::make(), Botan::PKCS5_PBKDF2::make(), Botan::make_block_cipher_mode(), Botan::make_block_cipher_mode_len(), Botan::make_block_cipher_mode_len2(), Botan::make_cbc_mode(), and Botan::make_ecb_mode().
{ if(i >= arg_count()) throw std::range_error("SCAN_Name::arg " + std::to_string(i) + " out of range for '" + as_string() + "'"); return args[i]; }
std::string Botan::SCAN_Name::arg | ( | size_t | i, |
const std::string & | def_value | ||
) | const |
i | which argument |
def_value | the default value |
Definition at line 164 of file scan_name.cpp.
References arg_count().
{ if(i >= arg_count()) return def_value; return args[i]; }
size_t Botan::SCAN_Name::arg_as_integer | ( | size_t | i, |
size_t | def_value | ||
) | const |
i | which argument |
def_value | the default value |
Definition at line 171 of file scan_name.cpp.
References arg_count(), and Botan::to_u32bit().
Referenced by Botan::PSSR::make(), Botan::RC4::make(), Botan::Skein_512::make(), Botan::make_block_cipher_mode_len(), and Botan::make_block_cipher_mode_len2().
size_t Botan::SCAN_Name::arg_count | ( | ) | const [inline] |
Definition at line 64 of file scan_name.h.
Referenced by all_arguments(), arg(), arg_as_integer(), Botan::hash_for_deterministic_signature(), Botan::OAEP::make(), Botan::Parallel::make(), Botan::Comb4P::make(), Botan::CBC_MAC::make(), Botan::HMAC::make(), Botan::OFB::make(), Botan::CTR_BE::make(), and Botan::CMAC::make().
{ return args.size(); }
bool Botan::SCAN_Name::arg_count_between | ( | size_t | lower, |
size_t | upper | ||
) | const [inline] |
lower | is the lower bound |
upper | is the upper bound |
Definition at line 71 of file scan_name.h.
Referenced by Botan::OAEP::make().
const std::string& Botan::SCAN_Name::as_string | ( | ) | const [inline] |
Definition at line 44 of file scan_name.h.
Referenced by arg().
{ return orig_algo_spec; }
std::string Botan::SCAN_Name::cipher_mode | ( | ) | const [inline] |
Definition at line 97 of file scan_name.h.
{ return (mode_info.size() >= 1) ? mode_info[0] : ""; }
std::string Botan::SCAN_Name::cipher_mode_pad | ( | ) | const [inline] |
Definition at line 103 of file scan_name.h.
{ return (mode_info.size() >= 2) ? mode_info[1] : ""; }
std::string Botan::SCAN_Name::deref_alias | ( | const std::string & | alias | ) | [static] |
Definition at line 209 of file scan_name.cpp.
Referenced by SCAN_Name().
{ std::lock_guard<std::mutex> lock(g_alias_map_mutex); std::string name = alias; for(auto i = g_alias_map.find(name); i != g_alias_map.end(); i = g_alias_map.find(name)) name = i->second; return name; }