Botan 3.14.1
Crypto and TLS for C&
Botan::AlgorithmPattern Class Referencefinal

#include <algorithm_spec.h>

Classes

struct  Element
class  InvalidAlgorithmPattern

Public Types

enum class  Type : uint8_t { Name , Int , Str }

Public Member Functions

template<size_t N>
consteval AlgorithmPattern (const char(&pattern)[N])
bool any_head () const
std::span< const Element > elements () const
std::span< const std::string_view > head_alternatives () const
std::string_view to_string () const

Static Public Attributes

static constexpr size_t MaxElements = 4
static constexpr size_t MaxHeadAlternatives = 4

Detailed Description

A compile-time validated pattern describing the accepted form of an algorithm specification. See AlgorithmSpec::match for how patterns are used.

Pattern grammar:

pattern := head [ '(' element (',' element)* ')' ] head := token ('|' token)* alternatives (aliases) | '' any head element := placeholder [ '...' ] '...' = one or more, must be last | literal a token which must appear | '[' literal ']' an optional literal, skipped if absent | token '(' element (',' element) ')' a literal with nested elements placeholder := '{' ident [':' type] ['=' default | '?'] '}' type := name | int | str default is name

A placeholder with a default ('=') or marked '?' is optional. Once an optional element appears, every following element must also be optional. Defaults are only permitted for int and str placeholders. An int must be a canonical decimal integer with no arguments; a str binds the text of the argument verbatim, including any nested arguments; a name binds the argument as a specification for passing on to another factory.

A '*' head matches any name, with AlgorithmMatch::head reporting which one. This is for provider wrappers which immediately look the head up in a table of supported algorithms; a factory pattern should always name its heads.

Patterns are only constructible from string literals, so a pattern and any match made from it may reference the pattern text indefinitely.

Definition at line 55 of file algorithm_spec.h.

Member Enumeration Documentation

◆ Type

enum class Botan::AlgorithmPattern::Type : uint8_t
strong
Enumerator
Name 
Int 
Str 

Definition at line 73 of file algorithm_spec.h.

73 : uint8_t {
74 Name,
75 Int,
76 Str,
77 };

Constructor & Destructor Documentation

◆ AlgorithmPattern()

template<size_t N>
Botan::AlgorithmPattern::AlgorithmPattern ( const char(&) pattern[N])
inlineconsteval

Construct a pattern from a string literal. The pattern is parsed and validated at compile time; a malformed pattern is a compile error.

Definition at line 95 of file algorithm_spec.h.

95 : // NOLINT(*-explicit-conversions,*-explicit-constructor)
96 AlgorithmPattern(std::string_view(pattern, N - 1)) {}
consteval AlgorithmPattern(const char(&pattern)[N])

References AlgorithmPattern().

Referenced by AlgorithmPattern().

Member Function Documentation

◆ any_head()

bool Botan::AlgorithmPattern::any_head ( ) const
inline
Returns
true if the pattern accepts any head

Definition at line 103 of file algorithm_spec.h.

103{ return m_head_count == 0; }

◆ elements()

std::span< const Element > Botan::AlgorithmPattern::elements ( ) const
inline

Definition at line 107 of file algorithm_spec.h.

107{ return std::span(m_elements).first(m_element_count); }

◆ head_alternatives()

std::span< const std::string_view > Botan::AlgorithmPattern::head_alternatives ( ) const
inline

Definition at line 105 of file algorithm_spec.h.

105{ return std::span(m_heads).first(m_head_count); }

◆ to_string()

std::string_view Botan::AlgorithmPattern::to_string ( ) const
inline

Definition at line 98 of file algorithm_spec.h.

98{ return m_text; }

Member Data Documentation

◆ MaxElements

size_t Botan::AlgorithmPattern::MaxElements = 4
staticconstexpr

Definition at line 57 of file algorithm_spec.h.

◆ MaxHeadAlternatives

size_t Botan::AlgorithmPattern::MaxHeadAlternatives = 4
staticconstexpr

Definition at line 59 of file algorithm_spec.h.


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