Botan 3.6.1
Crypto and TLS for C&
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, std::string_view 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 (std::string_view 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 22 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 56 of file scan_name.cpp.

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

◆ SCAN_Name() [2/2]

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

Create a SCAN_Name

Parameters
algo_specA SCAN-format name

Definition at line 58 of file scan_name.cpp.

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

References name.

Member Function Documentation

◆ algo_name()

◆ arg() [1/2]

◆ arg() [2/2]

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

Definition at line 126 of file scan_name.cpp.

126 {
127 if(i >= arg_count()) {
128 return std::string(def_value);
129 }
130 return m_args[i];
131}

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

140 {
141 return to_u32bit(arg(i));
142}
std::string arg(size_t i) const
uint32_t to_u32bit(std::string_view str_view)
Definition parsing.cpp:32

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

133 {
134 if(i >= arg_count()) {
135 return def_value;
136 }
137 return to_u32bit(m_args[i]);
138}

References Botan::to_u32bit().

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

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

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

References arg_count().

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

◆ 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.

89{ return (!m_mode_info.empty()) ? m_mode_info[0] : ""; }

Referenced by Botan::commoncrypto_opts_from_algo().

◆ 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.

94{ 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; }

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