1#ifndef LIBFILEZILLA_BASIC_TLS_PARAMS_HEADER
2#define LIBFILEZILLA_BASIC_TLS_PARAMS_HEADER
18template <
typename T,
typename Tag,
typename Policy>
19struct basic_tls_param;
21template <
typename T,
typename Tag>
22struct is_same_kind_of_basic_tls_param : std::false_type{};
24template <
typename T,
typename Tag,
typename Policy>
25struct is_same_kind_of_basic_tls_param<basic_tls_param<T, Tag, Policy>, Tag> : std::true_type{};
27template <
typename T,
typename Tag,
typename Policy>
28struct basic_tls_param final
30 basic_tls_param(basic_tls_param
const &) =
default;
31 basic_tls_param& operator=(basic_tls_param &&) =
default;
32 basic_tls_param& operator=(basic_tls_param
const &) =
default;
34 template <
typename U = T, std::enable_if_t<std::is_default_constructible_v<U>>* =
nullptr>
39 template <
typename U, std::enable_if_t<std::is_constructible_v<T, U>>* =
nullptr>
40 explicit basic_tls_param(U && v)
41 :
value(std::forward<U>(v))
44 template <
typename U,
typename V = std::remove_cv_t<std::remove_reference_t<U>>, std::enable_if_t<
45 !std::is_same_v<V, basic_tls_param> &&
46 is_same_kind_of_basic_tls_param<V, Tag>::value>* =
nullptr>
47 basic_tls_param(U && other)
51 explicit operator bool()
const
53 return Policy::is_valid(value);
58 return Policy::is_valid(value);
61 template <
typename U,
typename P>
62 bool operator ==(basic_tls_param<U, Tag, P>
const & rhs)
const
64 return value == rhs.value;
67 template <
typename U,
typename P>
68 bool operator !=(basic_tls_param<U, Tag, P>
const & rhs)
const
70 return value != rhs.value;
73 template <
typename U,
typename P>
74 bool operator <(basic_tls_param<U, Tag, P>
const & rhs)
const
76 return value < rhs.value;
79 template <
typename U,
typename P>
80 bool operator <=(basic_tls_param<U, Tag, P>
const & rhs)
const
82 return value <= rhs.value;
85 template <
typename U,
typename P>
86 bool operator >(basic_tls_param<U, Tag, P>
const & rhs)
const
88 return value > rhs.value;
91 template <
typename U,
typename P>
92 bool operator >=(basic_tls_param<U, Tag, P>
const & rhs)
const
94 return value >= rhs.value;
100struct basic_tls_param_policy
102 template <
typename T>
103 static bool is_valid(T
const & v)
109struct tls_pkcs11url_policy
111 static bool is_valid(std::string_view v)
113 static constexpr std::string_view pkcs11_scheme =
"pkcs11:";
120using basic_tls_blob = basic_tls_param<T, struct tls_blob_tag, basic_tls_param_policy>;
123using basic_tls_filepath = basic_tls_param<T, struct tls_filepath_tag, basic_tls_param_policy>;
126using basic_tls_pkcs11url = basic_tls_param<T, struct tls_pkcs11url_tag, tls_pkcs11url_policy>;
128template <
typename B,
typename F,
typename P>
129struct basic_tls_param_variant;
132struct is_basic_tls_param_variant : std::false_type{};
134template <
typename B,
typename F,
typename P>
135struct is_basic_tls_param_variant<basic_tls_param_variant<B, F, P>> : std::true_type{};
137template <
typename B,
typename F,
typename P>
138struct basic_tls_param_variant final
140 using blob_type = basic_tls_blob<B>;
141 using filepath_type = basic_tls_filepath<F>;
142 using pkcs11url_type = basic_tls_pkcs11url<P>;
144 using variant_type = std::variant<
150 blob_type
const *blob()
const
152 return std::get_if<blob_type>(&value);
155 filepath_type
const *filepath()
const
157 return std::get_if<filepath_type>(&value);
160 pkcs11url_type
const *pkcs11url()
const
162 return std::get_if<pkcs11url_type>(&value);
167 return std::get_if<blob_type>(&value);
170 filepath_type *filepath()
172 return std::get_if<filepath_type>(&value);
175 pkcs11url_type *pkcs11url()
177 return std::get_if<pkcs11url_type>(&value);
195 return fzT(
"pkcs11:<invalid>");
204 return fzT(
"blob:<invalid>");
208 return std::visit(visitor(), value);
211 basic_tls_param_variant() =
default;
212 basic_tls_param_variant(basic_tls_param_variant &&) =
default;
213 basic_tls_param_variant(basic_tls_param_variant
const &) =
default;
214 basic_tls_param_variant& operator=(basic_tls_param_variant &&) =
default;
215 basic_tls_param_variant& operator=(basic_tls_param_variant
const &) =
default;
217 template <
typename T, std::enable_if_t<std::is_constructible_v<variant_type, T>>* =
nullptr>
218 basic_tls_param_variant(T && v)
219 :
value(std::forward<T>(v))
222 template <
typename T,
typename U = std::remove_cv_t<std::remove_reference_t<T>>, std::enable_if_t<
223 !std::is_same_v<U, basic_tls_param_variant>
224 && is_basic_tls_param_variant<U>::value>* =
nullptr>
225 basic_tls_param_variant(T && other)
226 :
value(std::visit([](auto && v) {
227 return variant_type(std::forward<
decltype(v)>(v));
228 }, forward_like<T>(other.value)))
232 template <
typename T, std::enable_if_t<!std::is_same_v<T, basic_tls_param_variant> && is_basic_tls_param_variant<T>::value>* =
nullptr>
233 basic_tls_param_variant& operator=(T && other)
235 *
this = basic_tls_param_variant(std::forward<T>(other));
239 explicit operator bool()
const
241 return std::visit([](
auto && v) {
246 bool is_valid()
const
251 template <
typename F2,
typename P2,
typename B2>
252 bool operator ==(basic_tls_param_variant<F2, P2, B2>
const & rhs)
const
254 return value == rhs.value;
257 template <
typename F2,
typename P2,
typename B2>
258 bool operator !=(basic_tls_param_variant<F2, P2, B2>
const & rhs)
const
260 return value != rhs.value;
263 template <
typename F2,
typename P2,
typename B2>
264 bool operator <(basic_tls_param_variant<F2, P2, B2>
const & rhs)
const
266 return value < rhs.value;
269 template <
typename F2,
typename P2,
typename B2>
270 bool operator <=(basic_tls_param_variant<F2, P2, B2>
const & rhs)
const
272 return value <= rhs.value;
275 template <
typename F2,
typename P2,
typename B2>
276 bool operator >(basic_tls_param_variant<F2, P2, B2>
const & rhs)
const
278 return value > rhs.value;
281 template <
typename F2,
typename P2,
typename B2>
282 bool operator >=(basic_tls_param_variant<F2, P2, B2>
const & rhs)
const
284 return value >= rhs.value;
A function that acts like std::forward, but applies the value category of its first template paramete...
Collection of cryptographic hash and MAC functions.
The namespace used by libfilezilla.
Definition apply.hpp:17
constexpr detail::apply_value_category_t< T, U > forward_like(U &&u) noexcept
applies the value category of T to u, so that u can be perfectly forwarded as-if it were of type T.
Definition forward_like.hpp:31
std::enable_if_t< std::is_same_v< string_value_type_t< String >, string_value_type_t< Beginning > >, bool > starts_with(String const &s, Beginning const &beginning)
Tests whether the first string starts with the second string.
Definition string.hpp:825
std::vector< uint8_t > md5(std::string_view const &data)
Standard MD5.
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition string.hpp:69
std::string sprintf(std::string_view const &fmt, Args &&... args)
A simple type-safe sprintf replacement.
Definition format.hpp:456
native_string to_native(std::string_view const &in)
Converts std::string to native_string.
String types and assorted functions.
#define fzT(x)
Macro for a string literal in system-native character type. Note: Macro definition changes depending...
Definition string.hpp:324
@ value
Definition xml.hpp:36