Botan 2.19.1
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::SCAN_Name Class Referencefinal

#include <scan_name.h>

Public Member Functions

const std::string & algo_name () 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)
 
const std::string & to_string () const
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SCAN_Name() [1/2]

Botan::SCAN_Name::SCAN_Name ( const char *  algo_spec)
explicit

Create a SCAN_Name

Parameters
algo_specA SCAN-format name

Definition at line 59 of file scan_name.cpp.

59 : SCAN_Name(std::string(algo_spec))
60 {
61 }
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:59

◆ SCAN_Name() [2/2]

Botan::SCAN_Name::SCAN_Name ( std::string  algo_spec)
explicit

Create a SCAN_Name

Parameters
algo_specA SCAN-format name

Definition at line 63 of file scan_name.cpp.

63 : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info()
64 {
65 if(algo_spec.size() == 0)
66 throw Invalid_Argument("Expected algorithm name, got empty string");
67
68 std::vector<std::pair<size_t, std::string>> name;
69 size_t level = 0;
70 std::pair<size_t, std::string> accum = std::make_pair(level, "");
71
72 const std::string decoding_error = "Bad SCAN name '" + algo_spec + "': ";
73
74 for(size_t i = 0; i != algo_spec.size(); ++i)
75 {
76 char c = algo_spec[i];
77
78 if(c == '/' || c == ',' || c == '(' || c == ')')
79 {
80 if(c == '(')
81 ++level;
82 else if(c == ')')
83 {
84 if(level == 0)
85 throw Decoding_Error(decoding_error + "Mismatched parens");
86 --level;
87 }
88
89 if(c == '/' && level > 0)
90 accum.second.push_back(c);
91 else
92 {
93 if(accum.second != "")
94 name.push_back(accum);
95 accum = std::make_pair(level, "");
96 }
97 }
98 else
99 accum.second.push_back(c);
100 }
101
102 if(accum.second != "")
103 name.push_back(accum);
104
105 if(level != 0)
106 throw Decoding_Error(decoding_error + "Missing close paren");
107
108 if(name.size() == 0)
109 throw Decoding_Error(decoding_error + "Empty name");
110
111 m_alg_name = name[0].second;
112
113 bool in_modes = false;
114
115 for(size_t i = 1; i != name.size(); ++i)
116 {
117 if(name[i].first == 0)
118 {
119 m_mode_info.push_back(make_arg(name, i));
120 in_modes = true;
121 }
122 else if(name[i].first == 1 && !in_modes)
123 m_args.push_back(make_arg(name, i));
124 }
125 }
std::string name

References name.

Member Function Documentation

◆ algo_name()

const std::string & Botan::SCAN_Name::algo_name ( ) const
inline

◆ arg() [1/2]

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

Definition at line 127 of file scan_name.cpp.

128 {
129 if(i >= arg_count())
130 throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) +
131 " out of range for '" + to_string() + "'");
132 return m_args[i];
133 }
const std::string & to_string() const
Definition: scan_name.h:41
size_t arg_count() const
Definition: scan_name.h:56
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213

References arg_count(), to_string(), and Botan::ASN1::to_string().

Referenced by Botan::AEAD_Mode::create(), Botan::Cipher_Mode::create(), Botan::BlockCipher::create(), Botan::HashFunction::create(), Botan::KDF::create(), Botan::MessageAuthenticationCode::create(), Botan::PBKDF::create(), Botan::PasswordHashFamily::create(), Botan::StreamCipher::create(), Botan::PKCS11::MechanismWrapper::create_ecdh_mechanism(), Botan::get_eme(), Botan::get_emsa(), and Botan::hash_for_emsa().

◆ 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 135 of file scan_name.cpp.

136 {
137 if(i >= arg_count())
138 return def_value;
139 return m_args[i];
140 }

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 142 of file scan_name.cpp.

143 {
144 if(i >= arg_count())
145 return def_value;
146 return to_u32bit(m_args[i]);
147 }
uint32_t to_u32bit(const std::string &str)
Definition: parsing.cpp:35

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

Referenced by Botan::AEAD_Mode::create(), Botan::Cipher_Mode::create(), Botan::BlockCipher::create(), Botan::HashFunction::create(), Botan::MessageAuthenticationCode::create(), Botan::StreamCipher::create(), and Botan::get_emsa().

◆ arg_count()

size_t Botan::SCAN_Name::arg_count ( ) const
inline

◆ 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 63 of file scan_name.h.

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

Referenced by Botan::BlockCipher::create(), Botan::StreamCipher::create(), and Botan::get_emsa().

◆ as_string()

const std::string & Botan::SCAN_Name::as_string ( ) const
inline

Definition at line 43 of file scan_name.h.

44 {
45 return this->to_string();
46 }

References Botan::ASN1::to_string().

◆ cipher_mode()

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

Definition at line 89 of file scan_name.h.

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

Referenced by Botan::commoncrypto_opts_from_algo(), and Botan::X509_CA::X509_CA().

◆ cipher_mode_pad()

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

Definition at line 95 of file scan_name.h.

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

Referenced by Botan::commoncrypto_opts_from_algo().

◆ to_string()

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

Definition at line 41 of file scan_name.h.

41{ return m_orig_algo_spec; }

Referenced by arg().


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