9#ifndef BOTAN_STRONG_TYPE_H_
10#define BOTAN_STRONG_TYPE_H_
15#include <botan/concepts.h>
30template <
typename CapabilityT,
typename... Tags>
50 T&
get() {
return m_value; }
52 const T&
get()
const {
return m_value; }
61template <std::
integral T>
67template <concepts::container T>
88 template <
typename InputIt>
95 requires(std::same_as<T, std::string>)
99 decltype(
auto)
begin()
noexcept(
noexcept(this->
get().begin())) {
return this->
get().begin(); }
101 decltype(
auto)
begin()
const noexcept(
noexcept(this->
get().begin())) {
return this->
get().begin(); }
103 decltype(
auto)
end()
noexcept(
noexcept(this->
get().end())) {
return this->
get().end(); }
105 decltype(
auto)
end()
const noexcept(
noexcept(this->
get().end())) {
return this->
get().end(); }
107 decltype(
auto)
cbegin()
noexcept(
noexcept(this->
get().cbegin())) {
return this->
get().cbegin(); }
109 decltype(
auto)
cbegin()
const noexcept(
noexcept(this->
get().cbegin())) {
return this->
get().cbegin(); }
111 decltype(
auto)
cend()
noexcept(
noexcept(this->
get().cend())) {
return this->
get().cend(); }
113 decltype(
auto)
cend()
const noexcept(
noexcept(this->
get().cend())) {
return this->
get().cend(); }
117 decltype(
auto)
data()
noexcept(
noexcept(this->
get().data()))
120 return this->
get().data();
123 decltype(
auto)
data()
const noexcept(
noexcept(this->
get().data()))
126 return this->
get().data();
129 bool empty() const noexcept(noexcept(this->
get().empty()))
130 requires(concepts::has_empty<
T>)
132 return this->
get().empty();
138 this->
get().resize(size);
144 this->
get().reserve(size);
147 decltype(
auto)
operator[](
size_type i)
const noexcept(
noexcept(this->
get().operator[](i))) {
148 return this->
get()[i];
151 decltype(
auto)
operator[](
size_type i)
noexcept(
noexcept(this->
get().operator[](i))) {
return this->
get()[i]; }
167template <
typename T,
typename TagTypeT,
typename... Capabilities>
172 template <
typename CapabilityT>
174 return (std::is_same_v<CapabilityT, Capabilities> || ...);
178 using Tag = TagTypeT;
194template <
typename T,
typename... Tags>
195 requires(concepts::streamable<T>)
197 return os << v.
get();
200template <
typename T,
typename... Tags>
201 requires(std::equality_comparable<T>)
203 return lhs.
get() == rhs.
get();
206template <
typename T,
typename... Tags>
207 requires(std::three_way_comparable<T>)
209 return lhs.
get() <=> rhs.
get();
212template <std::integral T1, std::integral T2,
typename... Tags>
214 return a <=> b.
get();
217template <std::integral T1, std::integral T2,
typename... Tags>
219 return a.
get() <=> b;
222template <std::integral T1, std::integral T2,
typename... Tags>
227template <std::integral T1, std::integral T2,
typename... Tags>
232template <std::integral T1, std::integral T2,
typename... Tags>
238template <std::integral T1, std::integral T2,
typename... Tags>
244template <std::integral
T,
typename... Tags>
249template <std::integral T1, std::integral T2,
typename... Tags>
255template <std::integral T1, std::integral T2,
typename... Tags>
261template <std::integral
T,
typename... Tags>
266template <std::integral T1, std::integral T2,
typename... Tags>
272template <std::integral T1, std::integral T2,
typename... Tags>
278template <std::integral
T,
typename... Tags>
283template <std::integral T1, std::integral T2,
typename... Tags>
289template <std::integral T1, std::integral T2,
typename... Tags>
295template <std::integral
T,
typename... Tags>
300template <std::integral T1, std::integral T2,
typename... Tags>
306template <std::integral T1, std::integral T2,
typename... Tags>
312template <std::integral
T,
typename... Tags>
317template <std::integral T1, std::integral T2,
typename... Tags>
323template <std::integral T1, std::integral T2,
typename... Tags>
329template <std::integral
T,
typename... Tags>
334template <std::integral T1, std::integral T2,
typename... Tags>
340template <std::integral T1, std::integral T2,
typename... Tags>
346template <std::integral
T,
typename... Tags>
351template <std::integral T1, std::integral T2,
typename... Tags>
354 return Strong<T2, Tags...>(a >> b.
get());
357template <std::integral T1, std::integral T2,
typename... Tags>
360 return Strong<T1, Tags...>(a.
get() >> b);
363template <std::integral
T,
typename... Tags>
368template <std::integral T1, std::integral T2,
typename... Tags>
371 return Strong<T2, Tags...>(a << b.
get());
374template <std::integral T1, std::integral T2,
typename... Tags>
377 return Strong<T1, Tags...>(a.
get() << b);
380template <std::integral
T,
typename... Tags>
385template <std::integral T1, std::integral T2,
typename... Tags>
392template <std::integral
T,
typename... Tags>
398template <std::integral T1, std::integral T2,
typename... Tags>
405template <std::integral
T,
typename... Tags>
411template <std::integral T1, std::integral T2,
typename... Tags>
418template <std::integral
T,
typename... Tags>
424template <std::integral T1, std::integral T2,
typename... Tags>
431template <std::integral
T,
typename... Tags>
437template <std::integral T1, std::integral T2,
typename... Tags>
444template <std::integral
T,
typename... Tags>
450template <std::integral T1, std::integral T2,
typename... Tags>
457template <std::integral
T,
typename... Tags>
463template <std::integral T1, std::integral T2,
typename... Tags>
470template <std::integral
T,
typename... Tags>
476template <std::integral T1, std::integral T2,
typename... Tags>
483template <std::integral
T,
typename... Tags>
489template <std::integral T1, std::integral T2,
typename... Tags>
496template <std::integral
T,
typename... Tags>
502template <std::integral
T,
typename... Tags>
509template <std::integral
T,
typename... Tags>
515template <std::integral
T,
typename... Tags>
522template <std::integral
T,
typename... Tags>
543template <concepts::contiguous_strong_type T>
545 using underlying_span = std::
546 conditional_t<std::is_const_v<T>, std::span<const typename T::value_type>, std::span<typename T::value_type>>;
551 using iterator =
typename underlying_span::iterator;
552 using pointer =
typename underlying_span::pointer;
572 typename = std::enable_if_t<std::is_same_v<T2, std::remove_const_t<T>>>>
582 underlying_span
get()
const {
return m_span; }
587 underlying_span
get() {
return m_span; }
589 decltype(
auto)
data()
noexcept(
noexcept(this->m_span.data())) {
return this->m_span.data(); }
591 decltype(
auto)
data()
const noexcept(
noexcept(this->m_span.data())) {
return this->m_span.data(); }
593 decltype(
auto)
size()
const noexcept(
noexcept(this->m_span.size())) {
return this->m_span.size(); }
595 bool empty() const noexcept(noexcept(this->m_span.
empty())) {
return this->m_span.empty(); }
597 decltype(
auto)
begin()
noexcept(
noexcept(this->m_span.begin())) {
return this->m_span.begin(); }
599 decltype(
auto)
begin()
const noexcept(
noexcept(this->m_span.begin())) {
return this->m_span.begin(); }
601 decltype(
auto)
end()
noexcept(
noexcept(this->m_span.end())) {
return this->m_span.end(); }
603 decltype(
auto)
end()
const noexcept(
noexcept(this->m_span.end())) {
return this->m_span.end(); }
605 decltype(
auto)
operator[](
typename underlying_span::size_type i)
const noexcept {
return this->m_span[i]; }
608 underlying_span m_span;
typename underlying_span::size_type size_type
decltype(auto) begin() noexcept(noexcept(this->m_span.begin()))
decltype(auto) data() noexcept(noexcept(this->m_span.data()))
underlying_span get() const
StrongSpan(const StrongSpan< T2 > &other)
typename underlying_span::value_type value_type
decltype(auto) begin() const noexcept(noexcept(this->m_span.begin()))
StrongSpan(const StrongSpan &other)=default
decltype(auto) end() noexcept(noexcept(this->m_span.end()))
StrongSpan(underlying_span span)
typename underlying_span::const_pointer const_pointer
bool empty() const noexcept(noexcept(this->m_span.empty()))
typename underlying_span::pointer pointer
decltype(auto) data() const noexcept(noexcept(this->m_span.data()))
decltype(auto) end() const noexcept(noexcept(this->m_span.end()))
typename underlying_span::iterator iterator
decltype(auto) size() const noexcept(noexcept(this->m_span.size()))
static constexpr bool has_capability()
decltype(auto) data() const noexcept(noexcept(this->get().data()))
typename T::size_type size_type
Strong_Adapter(const char *str)
decltype(auto) end() const noexcept(noexcept(this->get().end()))
Strong_Adapter(size_t size)
void resize(size_type size) noexcept(noexcept(this->get().resize(size)))
typename T::iterator iterator
void reserve(size_type size) noexcept(noexcept(this->get().reserve(size)))
decltype(auto) begin() noexcept(noexcept(this->get().begin()))
size_type size() const noexcept(noexcept(this->get().size()))
decltype(auto) cbegin() noexcept(noexcept(this->get().cbegin()))
typename T::const_pointer const_pointer
typename T::pointer pointer
typename T::value_type value_type
decltype(auto) begin() const noexcept(noexcept(this->get().begin()))
decltype(auto) cend() const noexcept(noexcept(this->get().cend()))
decltype(auto) end() noexcept(noexcept(this->get().end()))
typename T::const_iterator const_iterator
bool empty() const noexcept(noexcept(this->get().empty()))
decltype(auto) data() noexcept(noexcept(this->get().data()))
Strong_Adapter(std::span< const value_type > span)
decltype(auto) cend() noexcept(noexcept(this->get().cend()))
decltype(auto) cbegin() const noexcept(noexcept(this->get().cbegin()))
Strong_Adapter(InputIt begin, InputIt end)
Strong_Base(Strong_Base &&) noexcept=default
Strong_Base(const Strong_Base &)=default
constexpr bool has_capability
ASN1_Type operator|(ASN1_Type x, ASN1_Type y)
BigInt operator*(const BigInt &x, const BigInt &y)
constexpr auto operator>>=(Strong< T1, Tags... > &a, T2 b)
OctetString operator^(const OctetString &k1, const OctetString &k2)
OctetString operator+(const OctetString &k1, const OctetString &k2)
constexpr auto operator++(Strong< T, Tags... > &a, int)
std::ostream & operator<<(std::ostream &out, const OID &oid)
BigInt operator/(const BigInt &x, const BigInt &y)
BigInt operator-(const BigInt &x, const BigInt &y)
constexpr auto operator/=(Strong< T1, Tags... > &a, T2 b)
constexpr auto operator|=(Strong< T1, Tags... > &a, T2 b)
constexpr auto operator<<=(Strong< T1, Tags... > &a, T2 b)
constexpr auto operator&=(Strong< T1, Tags... > &a, T2 b)
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
std::vector< uint8_t, Alloc > & operator^=(std::vector< uint8_t, Alloc > &out, const std::vector< uint8_t, Alloc2 > &in)
constexpr bool is_strong_span_v
std::vector< T, Alloc > & operator+=(std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
int operator>>(int fd, Pipe &pipe)
constexpr auto operator-=(Strong< T1, Tags... > &a, T2 b)
constexpr decltype(auto) unpack(T &t)
constexpr auto operator--(Strong< T, Tags... > &a, int)
auto operator<=>(const Strong< T, Tags... > &lhs, const Strong< T, Tags... > &rhs)
ECIES_Flags operator&(ECIES_Flags a, ECIES_Flags b)
constexpr auto operator*=(Strong< T1, Tags... > &a, T2 b)