Botan 3.9.0
Crypto and TLS for C&
Botan::detail::Bounded_XOF< XofT, bound > Class Template Referencefinal

#include <pqcrystals_helpers.h>

Public Member Functions

 Bounded_XOF ()
 Bounded_XOF (XofT xof)
template<size_t bytes, typename MapFnT = decltype(default_transformer<bytes>), typename PredicateFnT = decltype(default_predicate<bytes, MappedValueT<bytes, MapFnT>>)>
requires std::invocable<MapFnT, std::array<uint8_t, bytes>> && std::invocable<PredicateFnT, MappedValueT<bytes, MapFnT>>
constexpr auto next (const MapFnT &transformer=default_transformer< bytes >, const PredicateFnT &predicate=default_predicate< bytes, MappedValueT< bytes, MapFnT > >)
template<typename PredicateFnT = decltype(default_predicate<1, uint8_t>)>
requires std::invocable<PredicateFnT, uint8_t>
constexpr auto next_byte (PredicateFnT &&predicate=default_predicate< 1, uint8_t >)

Static Public Member Functions

template<size_t bytes, typename T>
static constexpr bool default_predicate (T)
template<size_t bytes>
static constexpr auto default_transformer (std::array< uint8_t, bytes > x)

Detailed Description

template<typename XofT, size_t bound>
requires requires(XofT xof) { { xof.template output<1>() } -> std::convertible_to<std::span<const uint8_t, 1>>; { xof.template output<42>() } -> std::convertible_to<std::span<const uint8_t, 42>>; }
class Botan::detail::Bounded_XOF< XofT, bound >

Wraps any XOF to limit the number of bytes that can be produced to bound. When the bound is reached, the XOF will throw an Internal_Error.

Definition at line 152 of file pqcrystals_helpers.h.

Constructor & Destructor Documentation

◆ Bounded_XOF() [1/2]

template<typename XofT, size_t bound>
Botan::detail::Bounded_XOF< XofT, bound >::Bounded_XOF ( )
inline

Definition at line 169 of file pqcrystals_helpers.h.

171 : m_bytes_consumed(0) {}

◆ Bounded_XOF() [2/2]

template<typename XofT, size_t bound>
Botan::detail::Bounded_XOF< XofT, bound >::Bounded_XOF ( XofT xof)
inlineexplicit

Definition at line 173 of file pqcrystals_helpers.h.

173: m_xof(xof), m_bytes_consumed(0) {}

Member Function Documentation

◆ default_predicate()

template<typename XofT, size_t bound>
template<size_t bytes, typename T>
constexpr bool Botan::detail::Bounded_XOF< XofT, bound >::default_predicate ( T )
inlinestaticconstexpr

Definition at line 164 of file pqcrystals_helpers.h.

164 {
165 return true;
166 }

◆ default_transformer()

template<typename XofT, size_t bound>
template<size_t bytes>
constexpr auto Botan::detail::Bounded_XOF< XofT, bound >::default_transformer ( std::array< uint8_t, bytes > x)
inlinestaticconstexpr

Definition at line 159 of file pqcrystals_helpers.h.

159 {
160 return x;
161 }

◆ next()

template<typename XofT, size_t bound>
template<size_t bytes, typename MapFnT = decltype(default_transformer<bytes>), typename PredicateFnT = decltype(default_predicate<bytes, MappedValueT<bytes, MapFnT>>)>
requires std::invocable<MapFnT, std::array<uint8_t, bytes>> && std::invocable<PredicateFnT, MappedValueT<bytes, MapFnT>>
auto Botan::detail::Bounded_XOF< XofT, bound >::next ( const MapFnT & transformer = default_transformer<bytes>,
const PredicateFnT & predicate = default_predicate<bytes, MappedValueT<bytes, MapFnT>> )
inlineconstexpr

Pulls the next bytes from the XOF and applies transformer to the output. The result is returned if predicate is fulfilled.

Returns
the transformed output of the XOF that fulfills predicate.

Definition at line 194 of file pqcrystals_helpers.h.

195 {
196 while(true) {
197 auto output = transformer(take<bytes>());
198 if(predicate(output)) {
199 return output;
200 }
201 }
202 }

Referenced by Botan::detail::Bounded_XOF< XOF &, bound >::next_byte().

◆ next_byte()

template<typename XofT, size_t bound>
template<typename PredicateFnT = decltype(default_predicate<1, uint8_t>)>
requires std::invocable<PredicateFnT, uint8_t>
auto Botan::detail::Bounded_XOF< XofT, bound >::next_byte ( PredicateFnT && predicate = default_predicate<1, uint8_t>)
inlineconstexpr
Returns
the next byte from the XOF that fulfills predicate.

Definition at line 180 of file pqcrystals_helpers.h.

180 {
181 return next<1>([](const auto bytes) { return bytes[0]; }, std::forward<PredicateFnT>(predicate));
182 }
constexpr auto next(const MapFnT &transformer=default_transformer< bytes >, const PredicateFnT &predicate=default_predicate< bytes, MappedValueT< bytes, MapFnT > >)

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