Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::SCAN_Name Class Reference

`#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)

## 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

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

Create a SCAN_Name

Parameters

  algo_spec | A SCAN-format name

Definition at line 57 of file scan_name.cpp.

57 : SCAN_Name(std::string(algo_spec))
58 {
59 }
Botan::SCAN_Name::SCAN_Name
SCAN_Name(const char *algo_spec)
Definition: scan_name.cpp:57

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

Create a SCAN_Name

Parameters

  algo_spec | A SCAN-format name

Definition at line 61 of file scan_name.cpp.

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

## Member Function Documentation

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

Returns
  algorithm name

Definition at line 45 of file scan_name.h.

Referenced by Botan::HashFunction::create(), Botan::BlockCipher::create(), Botan::StreamCipher::create(), Botan::PBKDF::create(), Botan::MessageAuthenticationCode::create(), Botan::KDF::create(), Botan::get_aead(), Botan::get_cipher_mode(), Botan::get_eme(), Botan::get_emsa(), and Botan::get_kdf().

45 { return m_alg_name; }

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

Parameters

  i | which argument

Returns
  ith argument

Definition at line 122 of file scan_name.cpp.

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

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

123 {
124 if(i >= arg_count())
125 throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) +
126 " out of range for '" + as_string() + "'");
127 return m_args[i];
128 }
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:50
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
Botan::SCAN_Name::as_string
const std::string & as_string() const
Definition: scan_name.h:40

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

References arg_count().

131 {
132 if(i >= arg_count())
133 return def_value;
134 return m_args[i];
135 }
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:50

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

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

Referenced by Botan::HashFunction::create(), Botan::BlockCipher::create(), Botan::StreamCipher::create(), Botan::MessageAuthenticationCode::create(), Botan::get_aead(), Botan::get_cipher_mode(), and Botan::get_emsa().

138 {
139 if(i >= arg_count())
140 return def_value;
141 return to_u32bit(m_args[i]);
142 }
Botan::to_u32bit
uint32_t to_u32bit(const std::string &str)
Definition: parsing.cpp:18
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:50

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

Returns
  number of arguments

Definition at line 50 of file scan_name.h.

Referenced by arg(), arg_as_integer(), Botan::HashFunction::create(), Botan::BlockCipher::create(), Botan::PBKDF::create(), Botan::MessageAuthenticationCode::create(), Botan::StreamCipher::create(), Botan::KDF::create(), Botan::PKCS11::MechanismWrapper::create_ecdh_mechanism(), Botan::get_aead(), Botan::get_cipher_mode(), Botan::get_eme(), Botan::get_emsa(), and Botan::hash_for_emsa().

50 { return m_args.size(); }

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

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

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

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

Returns
  original input string

Definition at line 40 of file scan_name.h.

Referenced by arg().

40 { return m_orig_algo_spec; }

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

Returns
  cipher mode (if any)

Definition at line 83 of file scan_name.h.

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

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

Returns
  cipher mode padding (if any)

Definition at line 89 of file scan_name.h.

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

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

- src/lib/base/scan_name.h
- src/lib/base/scan_name.cpp