9#ifndef BOTAN_STRONG_TYPE_H_
10#define BOTAN_STRONG_TYPE_H_
12#include <botan/concepts.h>
13#include <botan/strong_type_helpers.h>
23concept streamable =
requires(std::ostream& os, T a) { os << a; };
24template <
typename T,
typename Capability>
40template <
typename CapabilityT,
typename... Tags>
77 constexpr explicit
Strong_Base(T v) : m_value(std::move(v)) {}
81 constexpr T&
get() & {
return m_value; }
85 constexpr const T&
get() const& {
return m_value; }
89 constexpr T&&
get() && {
return std::move(m_value); }
93 constexpr const T&&
get() const&& {
return std::move(m_value); }
108template <std::
integral T>
117template <concepts::container T>
144 template <
typename InputIt>
150 decltype(
auto)
begin() noexcept(noexcept(this->
get().
begin())) {
return this->
get().begin(); }
154 decltype(
auto)
begin()
const noexcept(
noexcept(this->
get().begin())) {
return this->
get().begin(); }
158 decltype(
auto)
end()
noexcept(
noexcept(this->
get().end())) {
return this->
get().end(); }
162 decltype(
auto)
end()
const noexcept(
noexcept(this->
get().end())) {
return this->
get().end(); }
166 decltype(
auto)
cbegin()
noexcept(
noexcept(this->
get().cbegin())) {
return this->
get().cbegin(); }
170 decltype(
auto)
cbegin()
const noexcept(
noexcept(this->
get().cbegin())) {
return this->
get().cbegin(); }
174 decltype(
auto)
cend()
noexcept(
noexcept(this->
get().cend())) {
return this->
get().cend(); }
178 decltype(
auto)
cend()
const noexcept(
noexcept(this->
get().cend())) {
return this->
get().cend(); }
189 return this->
get().empty();
211 template <
typename U>
212 decltype(
auto)
operator[](U&& i)
const noexcept(
noexcept(this->
get().operator[](i))) {
213 return this->
get()[std::forward<U>(i)];
219 template <
typename U>
220 decltype(
auto)
operator[](U&& i)
noexcept(
noexcept(this->
get().operator[](i))) {
221 return this->
get()[std::forward<U>(i)];
225template <concepts::container T>
226class Strong_Adapter<T> :
public Container_Strong_Adapter_Base<T> {
228 using Container_Strong_Adapter_Base<T>::Container_Strong_Adapter_Base;
231template <concepts::contiguous_container T>
232class Strong_Adapter<T> :
public Container_Strong_Adapter_Base<T> {
247 requires(std::same_as<T, std::string>)
251 decltype(
auto)
data() noexcept(noexcept(this->
get().
data())) {
return this->
get().data(); }
253 decltype(
auto)
data()
const noexcept(
noexcept(this->
get().data())) {
return this->
get().data(); }
269template <
typename T,
typename TagTypeT,
typename... Capabilities>
278 template <
typename CapabilityT>
280 return (std::is_same_v<CapabilityT, Capabilities> || ...);
284 using Tag = TagTypeT;
293template <
typename T,
typename... Tags>
294 requires(concepts::streamable<T>)
296 return os << v.
get();
305template <
typename T,
typename... Tags>
306 requires(std::equality_comparable<T>)
308 return lhs.
get() == rhs.
get();
317template <
typename T,
typename... Tags>
318 requires(std::three_way_comparable<T>)
320 return lhs.
get() <=> rhs.
get();
329template <std::integral T1, std::integral T2,
typename... Tags>
331 return a <=> b.
get();
340template <std::integral T1, std::integral T2,
typename... Tags>
342 return a.
get() <=> b;
351template <std::integral T1, std::integral T2,
typename... Tags>
362template <std::integral T1, std::integral T2,
typename... Tags>
373template <std::integral T1, std::integral T2,
typename... Tags>
385template <std::integral T1, std::integral T2,
typename... Tags>
397template <std::integral T,
typename... Tags>
408template <std::integral T1, std::integral T2,
typename... Tags>
420template <std::integral T1, std::integral T2,
typename... Tags>
432template <std::integral T,
typename... Tags>
443template <std::integral T1, std::integral T2,
typename... Tags>
455template <std::integral T1, std::integral T2,
typename... Tags>
467template <std::integral T,
typename... Tags>
478template <std::integral T1, std::integral T2,
typename... Tags>
490template <std::integral T1, std::integral T2,
typename... Tags>
502template <std::integral T,
typename... Tags>
513template <std::integral T1, std::integral T2,
typename... Tags>
525template <std::integral T1, std::integral T2,
typename... Tags>
537template <std::integral T,
typename... Tags>
548template <std::integral T1, std::integral T2,
typename... Tags>
560template <std::integral T1, std::integral T2,
typename... Tags>
572template <std::integral T,
typename... Tags>
583template <std::integral T1, std::integral T2,
typename... Tags>
595template <std::integral T1, std::integral T2,
typename... Tags>
607template <std::integral T,
typename... Tags>
618template <std::integral T1, std::integral T2,
typename... Tags>
621 return Strong<T2, Tags...>(a >> b.
get());
630template <std::integral T1, std::integral T2,
typename... Tags>
633 return Strong<T1, Tags...>(a.
get() >> b);
642template <std::integral T,
typename... Tags>
653template <std::integral T1, std::integral T2,
typename... Tags>
656 return Strong<T2, Tags...>(a << b.
get());
665template <std::integral T1, std::integral T2,
typename... Tags>
668 return Strong<T1, Tags...>(a.
get() << b);
677template <std::integral T,
typename... Tags>
688template <std::integral T1, std::integral T2,
typename... Tags>
701template <std::integral T,
typename... Tags>
713template <std::integral T1, std::integral T2,
typename... Tags>
726template <std::integral T,
typename... Tags>
738template <std::integral T1, std::integral T2,
typename... Tags>
751template <std::integral T,
typename... Tags>
763template <std::integral T1, std::integral T2,
typename... Tags>
776template <std::integral T,
typename... Tags>
788template <std::integral T1, std::integral T2,
typename... Tags>
801template <std::integral T,
typename... Tags>
813template <std::integral T1, std::integral T2,
typename... Tags>
826template <std::integral T,
typename... Tags>
838template <std::integral T1, std::integral T2,
typename... Tags>
851template <std::integral T,
typename... Tags>
863template <std::integral T1, std::integral T2,
typename... Tags>
876template <std::integral T,
typename... Tags>
888template <std::integral T1, std::integral T2,
typename... Tags>
901template <std::integral T,
typename... Tags>
912template <std::integral T,
typename... Tags>
924template <std::integral T,
typename... Tags>
935template <std::integral T,
typename... Tags>
947template <std::integral T,
typename... Tags>
968template <concepts::contiguous_strong_type T>
970 using underlying_span = std::
971 conditional_t<std::is_const_v<T>, std::span<const typename T::value_type>, std::span<typename T::value_type>>;
981 using iterator =
typename underlying_span::iterator;
984 using pointer =
typename underlying_span::pointer;
1013 template <concepts::contiguous_strong_type T2>
1016 requires(std::is_same_v<T2, std::remove_const_t<T>>)
1017 : m_span(other.
get()) {}
1043 underlying_span
get()
const {
return m_span; }
1049 underlying_span
get() {
return m_span; }
1053 decltype(
auto)
data()
noexcept(
noexcept(this->m_span.data())) {
return this->m_span.data(); }
1057 decltype(
auto)
data()
const noexcept(
noexcept(this->m_span.data())) {
return this->m_span.data(); }
1061 decltype(
auto)
size()
const noexcept(
noexcept(this->m_span.size())) {
return this->m_span.size(); }
1065 bool empty() const noexcept(noexcept(this->m_span.
empty())) {
return this->m_span.empty(); }
1069 decltype(
auto)
begin() noexcept(noexcept(this->m_span.
begin())) {
return this->m_span.begin(); }
1073 decltype(
auto)
begin() const noexcept(noexcept(this->m_span.
begin())) {
return this->m_span.begin(); }
1077 decltype(
auto)
end() noexcept(noexcept(this->m_span.
end())) {
return this->m_span.end(); }
1081 decltype(
auto)
end() const noexcept(noexcept(this->m_span.
end())) {
return this->m_span.end(); }
1086 decltype(
auto)
operator[](
typename underlying_span::size_type i)
const noexcept {
return this->m_span[i]; }
1097 underlying_span m_span;
typename underlying_span::size_type size_type
The size type of the underlying span.
decltype(auto) begin() noexcept(noexcept(this->m_span.begin()))
StrongSpan()=default
Default constructor, creates an empty span.
StrongSpan< T > subspan(size_type offset, size_type count=std::dynamic_extent) const
decltype(auto) data() noexcept(noexcept(this->m_span.data()))
underlying_span get() const
typename underlying_span::value_type value_type
The element type of the underlying span.
decltype(auto) begin() const noexcept(noexcept(this->m_span.begin()))
StrongSpan(const StrongSpan &other)=default
StrongSpan(const StrongSpan< T2 > &other)
decltype(auto) end() noexcept(noexcept(this->m_span.end()))
StrongSpan & operator=(StrongSpan &&other)=default
StrongSpan(underlying_span span)
typename underlying_span::const_pointer const_pointer
The const pointer type of the underlying span.
bool empty() const noexcept(noexcept(this->m_span.empty()))
decltype(auto) operator[](typename underlying_span::size_type i) const noexcept
typename underlying_span::pointer pointer
The pointer type of the underlying span.
decltype(auto) data() const noexcept(noexcept(this->m_span.data()))
decltype(auto) end() const noexcept(noexcept(this->m_span.end()))
StrongSpan & operator=(const StrongSpan &other)=default
typename underlying_span::iterator iterator
The iterator type of the underlying span.
StrongSpan(StrongSpan &&other)=default
decltype(auto) size() const noexcept(noexcept(this->m_span.size()))
static constexpr bool has_capability()
typename T::iterator iterator
The iterator type of the wrapped container.
typename T::value_type value_type
The element type of the wrapped container.
decltype(auto) cbegin() const noexcept(noexcept(this->get().cbegin()))
decltype(auto) begin() noexcept(noexcept(this->get().begin()))
Container_Strong_Adapter_Base(InputIt begin, InputIt end)
decltype(auto) cend() noexcept(noexcept(this->get().cend()))
typename T::size_type size_type
The size type of the wrapped container.
decltype(auto) cend() const noexcept(noexcept(this->get().cend()))
decltype(auto) end() const noexcept(noexcept(this->get().end()))
void reserve(size_type size) noexcept(noexcept(this->get().reserve(size)))
size_type size() const noexcept(noexcept(this->get().size()))
decltype(auto) end() noexcept(noexcept(this->get().end()))
bool empty() const noexcept(noexcept(this->get().empty()))
decltype(auto) begin() const noexcept(noexcept(this->get().begin()))
Container_Strong_Adapter_Base(size_t size)
void resize(size_type size) noexcept(noexcept(this->get().resize(size)))
typename T::const_iterator const_iterator
The const iterator type of the wrapped container.
decltype(auto) cbegin() noexcept(noexcept(this->get().cbegin()))
Strong_Adapter(const char *str)
decltype(auto) data() const noexcept(noexcept(this->get().data()))
decltype(auto) data() noexcept(noexcept(this->get().data()))
typename T::const_pointer const_pointer
typename T::pointer pointer
Strong_Adapter(std::span< const typename Container_Strong_Adapter_Base< T >::value_type > span)
T wrapped_type
The type wrapped by this strong type.
constexpr const T & get() const &
Strong_Base(Strong_Base &&) noexcept=default
Move constructor.
Strong_Base()=default
Default constructor, value initializes the wrapped value.
constexpr const T && get() const &&
Strong_Base(const Strong_Base &)=default
Copy constructor.
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)
constexpr auto operator>>=(Strong< T1, Tags... > &a, T2 b)
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)
std::vector< uint8_t, Alloc > & operator^=(std::vector< uint8_t, Alloc > &out, const std::vector< uint8_t, Alloc2 > &in)
auto operator<=>(const Strong< T, Tags... > &lhs, const Strong< T, Tags... > &rhs)
std::vector< T, Alloc > & operator+=(std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
int operator>>(int fd, Pipe &pipe)
bool operator==(const AlgorithmIdentifier &x, const AlgorithmIdentifier &y)
constexpr auto operator*=(Strong< T1, Tags... > &a, T2 b)
constexpr auto operator--(Strong< T, Tags... > &a, int)
constexpr auto operator/=(Strong< T1, Tags... > &a, T2 b)
constexpr auto operator-=(Strong< T1, Tags... > &a, T2 b)
ECIES_Flags operator&(ECIES_Flags a, ECIES_Flags b)