Botan 1.10.17
Botan::SCAN_Name Class Reference

#include <scan_name.h>

Public Member Functions

std::string algo_name () const
std::string algo_name_and_args () 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
std::string as_string () const
std::string cipher_mode () const
std::string cipher_mode_pad () const
 SCAN_Name (std::string algo_spec)

Detailed Description

A class encapsulating a SCAN name (similar to JCE conventions) http://www.users.zetnet.co.uk/hopwood/crypto/scan/

Definition at line 21 of file scan_name.h.

Constructor & Destructor Documentation

◆ SCAN_Name()

Botan::SCAN_Name::SCAN_Name ( std::string algo_spec)
Parameters
algo_specA SCAN-format name

Definition at line 66 of file scan_name.cpp.

67 {
68 orig_algo_spec = algo_spec;
69
70 std::vector<std::pair<size_t, std::string> > name;
71 size_t level = 0;
72 std::pair<size_t, std::string> accum = std::make_pair(level, "");
73
74 std::string decoding_error = "Bad SCAN name '" + algo_spec + "': ";
75
76 algo_spec = global_state().deref_alias(algo_spec);
77
78 for(size_t i = 0; i != algo_spec.size(); ++i)
79 {
80 char c = algo_spec[i];
81
82 if(c == '/' || c == ',' || c == '(' || c == ')')
83 {
84 if(c == '(')
85 ++level;
86 else if(c == ')')
87 {
88 if(level == 0)
89 throw Decoding_Error(decoding_error + "Mismatched parens");
90 --level;
91 }
92
93 if(c == '/' && level > 0)
94 accum.second.push_back(c);
95 else
96 {
97 if(accum.second != "")
98 name.push_back(deref_aliases(accum));
99 accum = std::make_pair(level, "");
100 }
101 }
102 else
103 accum.second.push_back(c);
104 }
105
106 if(accum.second != "")
107 name.push_back(deref_aliases(accum));
108
109 if(level != 0)
110 throw Decoding_Error(decoding_error + "Missing close paren");
111
112 if(name.size() == 0)
113 throw Decoding_Error(decoding_error + "Empty name");
114
115 alg_name = name[0].second;
116
117 bool in_modes = false;
118
119 for(size_t i = 1; i != name.size(); ++i)
120 {
121 if(name[i].first == 0)
122 {
123 mode_info.push_back(make_arg(name, i));
124 in_modes = true;
125 }
126 else if(name[i].first == 1 && !in_modes)
127 args.push_back(make_arg(name, i));
128 }
129 }
std::string deref_alias(const std::string &alias) const
Definition libstate.cpp:162
Library_State & global_state()
Decoding_Error(const std::string &name)
Definition exceptn.h:140

References Botan::Decoding_Error::Decoding_Error(), Botan::Library_State::deref_alias(), and Botan::global_state().

Member Function Documentation

◆ algo_name()

◆ algo_name_and_args()

std::string Botan::SCAN_Name::algo_name_and_args ( ) const
Returns
algorithm name plus any arguments

Definition at line 131 of file scan_name.cpp.

132 {
133 std::string out;
134
135 out = algo_name();
136
137 if(arg_count())
138 {
139 out += '(';
140 for(size_t i = 0; i != arg_count(); ++i)
141 {
142 out += arg(i);
143 if(i != arg_count() - 1)
144 out += ',';
145 }
146 out += ')';
147
148 }
149
150 return out;
151 }
std::string arg(size_t i) const
size_t arg_count() const
Definition scan_name.h:47
std::string algo_name() const
Definition scan_name.h:37

References algo_name(), arg(), and arg_count().

Referenced by Botan::algorithm_kat().

◆ arg() [1/2]

std::string Botan::SCAN_Name::arg ( size_t i) const
Parameters
iwhich argument
Returns
ith argument

Definition at line 153 of file scan_name.cpp.

154 {
155 if(i >= arg_count())
156 throw std::range_error("SCAN_Name::argument - i out of range");
157 return args[i];
158 }

References arg_count().

Referenced by algo_name_and_args(), Botan::Core_Engine::find_block_cipher(), Botan::Core_Engine::find_hash(), Botan::Core_Engine::find_mac(), Botan::Core_Engine::find_pbkdf(), Botan::get_eme(), Botan::get_emsa(), Botan::get_kdf(), Botan::get_pbe(), and Botan::get_pbe().

◆ arg() [2/2]

std::string Botan::SCAN_Name::arg ( size_t i,
const std::string & def_value ) const
Parameters
iwhich argument
def_valuethe default value
Returns
ith argument or the default value

Definition at line 160 of file scan_name.cpp.

161 {
162 if(i >= arg_count())
163 return def_value;
164 return args[i];
165 }

References arg_count().

◆ arg_as_integer()

size_t Botan::SCAN_Name::arg_as_integer ( size_t i,
size_t def_value ) const
Parameters
iwhich argument
def_valuethe default value
Returns
ith argument as an integer, or the default value

Definition at line 167 of file scan_name.cpp.

168 {
169 if(i >= arg_count())
170 return def_value;
171 return to_u32bit(args[i]);
172 }
u32bit to_u32bit(const std::string &number)
Definition parsing.cpp:18

References arg_count(), and Botan::to_u32bit().

Referenced by Botan::Core_Engine::find_block_cipher(), Botan::OpenSSL_Engine::find_block_cipher(), Botan::Core_Engine::find_hash(), Botan::Core_Engine::find_stream_cipher(), Botan::OpenSSL_Engine::find_stream_cipher(), and Botan::get_emsa().

◆ arg_count()

◆ arg_count_between()

bool Botan::SCAN_Name::arg_count_between ( size_t lower,
size_t upper ) const
inline
Parameters
loweris the lower bound
upperis the upper bound
Returns
if the number of arguments is between lower and upper

Definition at line 54 of file scan_name.h.

55 { return ((arg_count() >= lower) && (arg_count() <= upper)); }

References arg_count().

Referenced by Botan::Core_Engine::find_block_cipher(), Botan::get_eme(), and Botan::get_emsa().

◆ as_string()

std::string Botan::SCAN_Name::as_string ( ) const
inline
Returns
original input string

Definition at line 32 of file scan_name.h.

32{ return orig_algo_spec; }

Referenced by Botan::get_pbe().

◆ cipher_mode()

std::string Botan::SCAN_Name::cipher_mode ( ) const
inline
Returns
cipher mode (if any)

Definition at line 80 of file scan_name.h.

81 { return (mode_info.size() >= 1) ? mode_info[0] : ""; }

Referenced by Botan::algorithm_kat().

◆ cipher_mode_pad()

std::string Botan::SCAN_Name::cipher_mode_pad ( ) const
inline
Returns
cipher mode padding (if any)

Definition at line 86 of file scan_name.h.

87 { return (mode_info.size() >= 2) ? mode_info[1] : ""; }

Referenced by Botan::algorithm_kat().


The documentation for this class was generated from the following files: