Botan 3.0.0-rc1
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, 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 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_view  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 '" + m_orig_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

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

138 {
139 if(i >= arg_count())
140 return std::string(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(std::string_view str_view)
Definition: parsing.cpp:31

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(), Botan::StreamCipher::create(), and Botan::PSS_Params::from_emsa_name().

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

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

90 { return (m_mode_info.size() >= 1) ? 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 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 40 of file scan_name.h.

40{ return m_orig_algo_spec; }

Referenced by arg().


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