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

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

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

Referenced by arg_as_integer(), Botan::AEAD_Mode::create(), Botan::Cipher_Mode::create(), Botan::EME::create(), Botan::EMSA::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(), 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 137 of file scan_name.cpp.

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

References arg_count().

◆ arg_as_integer() [1/2]

size_t Botan::SCAN_Name::arg_as_integer ( size_t  i) const
Parameters
iwhich argument
Returns
ith argument as an integer

Definition at line 151 of file scan_name.cpp.

152 {
153 return to_u32bit(arg(i));
154 }
std::string arg(size_t i) const
Definition: scan_name.cpp:129
uint32_t to_u32bit(const std::string &str)
Definition: parsing.cpp:29

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

◆ arg_as_integer() [2/2]

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

145 {
146 if(i >= arg_count())
147 return def_value;
148 return to_u32bit(m_args[i]);
149 }

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

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

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

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

References arg_count().

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

◆ cipher_mode()

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

Definition at line 88 of file scan_name.h.

89 { 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 94 of file scan_name.h.

95 { 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 39 of file scan_name.h.

39{ return m_orig_algo_spec; }

Referenced by arg().


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