libfilezilla
tls_params.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_TLS_PARAMS_HEADER
2 #define LIBFILEZILLA_TLS_PARAMS_HEADER
3 
51 #include "basic_tls_params.hpp"
52 
53 namespace fz {
54 
58 template <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>
59 basic_tls_blob<T> tls_blob(T && v)
60 {
61  return basic_tls_blob<T>{ std::forward<T>(v) };
62 }
63 
70 template <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>
71 basic_tls_blob<std::string> tls_blob(T && v)
72 {
73  return basic_tls_blob<std::string>{ std::forward<T>(v) };
74 }
75 
79 template <typename T, std::enable_if_t<std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, native_string>>* = nullptr>
80 basic_tls_filepath<T> tls_filepath(T && v)
81 {
82  return basic_tls_filepath<T>{ std::forward<T>(v) };
83 }
84 
91 template <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>
92 basic_tls_filepath<native_string>
93 tls_filepath(T && v)
94 {
95  return basic_tls_filepath<native_string>{ std::forward<T>(v) };
96 }
97 
101 template <typename T, std::enable_if_t<std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, std::string>>* = nullptr>
102 basic_tls_pkcs11url<T> tls_pkcs11url(T && v)
103 {
104  return basic_tls_pkcs11url<T>{ std::forward<T>(v) };
105 }
106 
113 template <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>
114 basic_tls_pkcs11url<std::string> tls_pkcs11url(T && v)
115 {
116  return basic_tls_pkcs11url<std::string>{ std::forward<T>(v) };
117 }
118 
120 using const_tls_param_ref = basic_tls_param_variant<
121  std::string_view const,
122  native_string const &,
123  std::string const &
124 >;
125 
127 using tls_param_ref = basic_tls_param_variant<
128  std::string &,
129  native_string const &,
130  std::string const &
131 >;
132 
134 using tls_param = basic_tls_param_variant<
135  std::string,
137  std::string
138 >;
139 
141 enum class tls_data_format
142 {
143  autodetect,
144  pem,
145  der
146 };
147 
149 inline 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
basic_tls_filepath< T > tls_filepath(T &&v)
Creates a tls_filepath object.
Definition: tls_params.hpp:80
bool starts_with(String const &s, String const &beginning)
Tests whether the first string starts with the second string.
Definition: string.hpp:663
basic_tls_param_variant< std::string, native_string, std::string > tls_param
Acts as an instance of one of a fz::tls_blob, fz::tls_filepath or fz::tls_pkcs11url.
Definition: tls_params.hpp:138
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:141
The provided data is in PEM format.
basic_tls_blob< T > tls_blob(T &&v)
Creates a tls_blob object.
Definition: tls_params.hpp:59
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 fz::tls_blob, fz::tls_filepath or fz::tls_pkcs11url.
Definition: tls_params.hpp:124
The provided data is in DER format.
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:34
basic_tls_pkcs11url< T > tls_pkcs11url(T &&v)
Creates a tls_pkcs11url object.
Definition: tls_params.hpp:102
The namespace used by libfilezilla.
Definition: apply.hpp:17
The type will be detected automatically using an heuristic.
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
basic_tls_param_variant< std::string &, native_string const &, std::string const & > tls_param_ref
Acts as a lvalue reference to one of a fz::tls_blob, fz::tls_filepath or fz::tls_pkcs11url.
Definition: tls_params.hpp:131