Botan: Botan::SCAN_Name Class Reference

Botan 1.10.17

Public Member Functions | List of all members
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_spec | A SCAN-format name

Definition at line 66 of file scan_name.cpp.

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

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 }
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32
Botan::Library_State::deref_alias
std::string deref_alias(const std::string &alias) const
Definition: libstate.cpp:162

## Member Function Documentation

## ◆ algo_name()

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

Returns
  algorithm name

Definition at line 37 of file scan_name.h.

Referenced by algo_name_and_args(), Botan::Assembler_Engine::find_block_cipher(), Botan::SIMD_Engine::find_block_cipher(), Botan::AES_ISA_Engine::find_block_cipher(), Botan::Core_Engine::find_block_cipher(), Botan::OpenSSL_Engine::find_block_cipher(), Botan::Assembler_Engine::find_hash(), Botan::SIMD_Engine::find_hash(), Botan::Core_Engine::find_hash(), Botan::OpenSSL_Engine::find_hash(), Botan::Core_Engine::find_mac(), Botan::Core_Engine::find_pbkdf(), Botan::Core_Engine::find_stream_cipher(), Botan::OpenSSL_Engine::find_stream_cipher(), Botan::get_eme(), Botan::get_emsa(), Botan::get_kdf(), and Botan::get_pbe().

37 { return alg_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.

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

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 }
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47
Botan::SCAN_Name::arg
std::string arg(size_t i) const
Definition: scan_name.cpp:153
Botan::SCAN_Name::algo_name
std::string algo_name() const
Definition: scan_name.h:37

## ◆ arg() [1/2]

std::string Botan::SCAN_Name::arg | ( | size_t | i | ) | const

Parameters

  i | which argument

Returns
  ith argument

Definition at line 153 of file scan_name.cpp.

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(), and Botan::get_pbe().

154 {
155 if(i >= arg_count())
156 throw std::range_error("SCAN_Name::argument - i out of range");
157 return args[i];
158 }
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47

## ◆ arg() [2/2]

std::string Botan::SCAN_Name::arg | ( | size_t | i,
|  | const std::string & | def_value
| ) |  | const

Parameters

  i | which argument
  def_value | the default value

Returns
  ith argument or the default value

Definition at line 160 of file scan_name.cpp.

References arg_count().

161 {
162 if(i >= arg_count())
163 return def_value;
164 return args[i];
165 }
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47

## ◆ arg_as_integer()

size_t Botan::SCAN_Name::arg_as_integer | ( | size_t | i,
|  | size_t | def_value
| ) |  | const

Parameters

  i | which argument
  def_value | the default value

Returns
  ith argument as an integer, or the default value

Definition at line 167 of file scan_name.cpp.

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::OpenSSL_Engine::find_stream_cipher(), Botan::Core_Engine::find_stream_cipher(), and Botan::get_emsa().

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

## ◆ arg_count()

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

Returns
  number of arguments

Definition at line 47 of file scan_name.h.

Referenced by algo_name_and_args(), arg(), arg_as_integer(), 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(), and Botan::get_pbe().

47 { return args.size(); }

## ◆ arg_count_between()

bool Botan::SCAN_Name::arg_count_between | ( | size_t | lower,
|  | size_t | upper
| ) |  | const
| inline

Parameters

  lower | is the lower bound
  upper | is the upper bound

Returns
  if the number of arguments is between lower and upper

Definition at line 54 of file scan_name.h.

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

55 { return ((arg_count() >= lower) && (arg_count() <= upper)); }
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:47

## ◆ as_string()

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

Returns
  original input string

Definition at line 32 of file scan_name.h.

Referenced by Botan::get_pbe().

32 { return orig_algo_spec; }

## ◆ 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] : ""; }

## ◆ 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] : ""; }

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

- src/libstate/scan_name.h
- src/libstate/scan_name.cpp