libfilezilla
Loading...
Searching...
No Matches
tls_params.hpp
Go to the documentation of this file.
1#ifndef LIBFILEZILLA_TLS_PARAMS_HEADER
2#define LIBFILEZILLA_TLS_PARAMS_HEADER
3
50
51#include "basic_tls_params.hpp"
52
53namespace fz {
54
58template <typename T, std::enable_if_t<std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, std::string> || std::is_same_v<T, std::string_view>>* = nullptr>
59basic_tls_blob<T> tls_blob(T && v)
60{
61 return basic_tls_blob<T>{ std::forward<T>(v) };
62}
63
70template <typename T, std::enable_if_t<!(std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, std::string> || std::is_same_v<T, std::string_view>) && std::is_constructible_v<std::string, T>>* = nullptr>
71basic_tls_blob<std::string> tls_blob(T && v)
72{
73 return basic_tls_blob<std::string>{ std::forward<T>(v) };
74}
75
79template <typename T, std::enable_if_t<std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, native_string>>* = nullptr>
80basic_tls_filepath<T> tls_filepath(T && v)
81{
82 return basic_tls_filepath<T>{ std::forward<T>(v) };
83}
84
91template <typename T, std::enable_if_t<!(std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, native_string>) && std::is_constructible_v<native_string, T>>* = nullptr>
92basic_tls_filepath<native_string>
94{
95 return basic_tls_filepath<native_string>{ std::forward<T>(v) };
96}
97
101template <typename T, std::enable_if_t<std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, std::string>>* = nullptr>
102basic_tls_pkcs11url<T> tls_pkcs11url(T && v)
103{
104 return basic_tls_pkcs11url<T>{ std::forward<T>(v) };
105}
106
113template <typename T, std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, std::string> && std::is_constructible_v<std::string, T>>* = nullptr>
114basic_tls_pkcs11url<std::string> tls_pkcs11url(T && v)
115{
116 return basic_tls_pkcs11url<std::string>{ std::forward<T>(v) };
117}
118
120using const_tls_param_ref = basic_tls_param_variant<
121 std::string_view const,
122 native_string const &,
123 std::string const &
124>;
125
127using tls_param_ref = basic_tls_param_variant<
128 std::string &,
129 native_string const &,
130 std::string const &
131>;
132
134using tls_param = basic_tls_param_variant<
135 std::string,
137 std::string
138>;
139
147
149inline bool is_pem(std::string_view blob)
150{
151 constexpr std::string_view delimiters{" \n\r\t"};
152 constexpr std::string_view pem_begin{"-----BEGIN"};
153
154 auto pos = blob.find_first_not_of(delimiters);
155 return pos != blob.npos && starts_with(blob.substr(pos), pem_begin);
156}
157
158}
159
160#endif
The namespace used by libfilezilla.
Definition apply.hpp:17
basic_tls_param_variant< std::string, native_string, std::string > tls_param
Acts as an instance of one of a tls_blob, tls_filepath or tls_pkcs11url.
Definition tls_params.hpp:134
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition string.hpp:36
basic_tls_pkcs11url< T > tls_pkcs11url(T &&v)
Creates a tls_pkcs11url object.
Definition tls_params.hpp:102
bool is_pem(std::string_view blob)
returns true if the blob is in PEM format. Uses a simple heuristic.
Definition tls_params.hpp:149
bool starts_with(String const &s, String const &beginning)
Tests whether the first string starts with the second string.
Definition string.hpp:759
basic_tls_filepath< T > tls_filepath(T &&v)
Creates a tls_filepath object.
Definition tls_params.hpp:80
basic_tls_param_variant< std::string_view const, native_string const &, std::string const & > const_tls_param_ref
Acts as a const lvalue reference to one of a tls_blob, tls_filepath or tls_pkcs11url.
Definition tls_params.hpp:120
basic_tls_blob< T > tls_blob(T &&v)
Creates a tls_blob object.
Definition tls_params.hpp:59
tls_data_format
The encoding type of a fz::tls_blob or the file pointed to by a fz::tls_filepath.
Definition tls_params.hpp:142
@ autodetect
The type will be detected automatically using an heuristic.
Definition tls_params.hpp:143
@ der
The provided data is in DER format.
Definition tls_params.hpp:145
@ pem
The provided data is in PEM format.
Definition tls_params.hpp:144
basic_tls_param_variant< std::string &, native_string const &, std::string const & > tls_param_ref
Acts as a lvalue reference to one of a tls_blob, tls_filepath or tls_pkcs11url.
Definition tls_params.hpp:127