OGLplus  (0.59.0) a C++ wrapper for rendering APIs

ssl_api.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_SSL_API_HPP
9 #define EAGINE_SSL_API_HPP
10 
11 #include "memory/block.hpp"
12 #include "ssl_api/api.hpp"
13 #include "ssl_api/api_traits.hpp"
14 #include "ssl_api/constants.hpp"
15 #include "ssl_api_fwd.hpp"
16 
17 namespace eagine::sslp {
18 //------------------------------------------------------------------------------
19 template <typename ApiTraits>
20 class basic_ssl_api
21  : protected ApiTraits
22  , public basic_ssl_operations<ApiTraits>
23  , public basic_ssl_constants<ApiTraits> {
24 public:
25  template <typename R>
26  using combined_result = typename ApiTraits::template combined_result<R>;
27 
28  using evp_md_type = ssl_types::evp_md_type;
29 
30  basic_ssl_api(ApiTraits traits)
31  : ApiTraits{std::move(traits)}
32  , basic_ssl_operations<ApiTraits>{*static_cast<ApiTraits*>(this)}
33  , basic_ssl_constants<ApiTraits>{
34  *static_cast<ApiTraits*>(this),
35  *static_cast<basic_ssl_operations<ApiTraits>*>(this)} {}
36 
37  basic_ssl_api()
38  : basic_ssl_api{ApiTraits{}} {}
39 
40  template <typename Function>
41  void for_each_engine(Function function) const {
42  if(auto opt_eng = this->get_first_engine()) {
43  owned_engine eng = std::move(extract(opt_eng));
44  while(eng) {
45  function(engine(eng));
46  opt_eng = this->get_next_engine(eng);
47  if(opt_eng) {
48  eng = std::move(extract(opt_eng));
49  }
50  }
51  }
52  }
53 
54  auto data_digest(
56  memory::block dst,
57  message_digest_type mdtype) const noexcept -> memory::block;
58 
59  template <typename OptMdt>
60  auto do_data_digest(
62  memory::block dst,
63  OptMdt opt_mdtype) const noexcept -> memory::block {
64  if(opt_mdtype) {
65  return data_digest(data, dst, extract(opt_mdtype));
66  }
67  return {};
68  }
69 
70  auto md5_digest(memory::const_block data, memory::block dst) const noexcept {
71  return do_data_digest(data, dst, this->message_digest_md5());
72  }
73 
74  auto
75  sha1_digest(memory::const_block data, memory::block dst) const noexcept {
76  return do_data_digest(data, dst, this->message_digest_sha1());
77  }
78 
79  auto
80  sha224_digest(memory::const_block data, memory::block dst) const noexcept {
81  return do_data_digest(data, dst, this->message_digest_sha224());
82  }
83 
84  auto
85  sha256_digest(memory::const_block data, memory::block dst) const noexcept {
86  return do_data_digest(data, dst, this->message_digest_sha256());
87  }
88 
89  auto
90  sha384_digest(memory::const_block data, memory::block dst) const noexcept {
91  return do_data_digest(data, dst, this->message_digest_sha384());
92  }
93 
94  auto
95  sha512_digest(memory::const_block data, memory::block dst) const noexcept {
96  return do_data_digest(data, dst, this->message_digest_sha512());
97  }
98 
99  auto sign_data_digest(
100  memory::const_block data,
101  memory::block dst,
102  message_digest_type mdtype,
103  pkey pky) const noexcept -> memory::block;
104 
105  auto verify_data_digest(
106  memory::const_block data,
108  message_digest_type mdtype,
109  pkey pky) const noexcept -> bool;
110 
111  auto parse_private_key(
113  password_callback get_passwd = {}) const noexcept
114  -> combined_result<owned_pkey>;
115 
116  auto parse_public_key(
118  password_callback get_passwd = {}) const noexcept
119  -> combined_result<owned_pkey>;
120 
121  auto parse_x509(memory::const_block blk, password_callback get_passwd = {})
122  const noexcept -> combined_result<owned_x509>;
123 
124  auto ca_verify_certificate(string_view ca_file_path, x509) const noexcept
125  -> bool;
126 
127  auto ca_verify_certificate(x509 ca_cert, x509) const noexcept -> bool;
128 };
129 //------------------------------------------------------------------------------
130 template <std::size_t I, typename ApiTraits>
131 auto get(basic_ssl_api<ApiTraits>& x) noexcept ->
132  typename std::tuple_element<I, basic_ssl_api<ApiTraits>>::type& {
133  return x;
134 }
135 
136 template <std::size_t I, typename ApiTraits>
137 auto get(const basic_ssl_api<ApiTraits>& x) noexcept -> const
138  typename std::tuple_element<I, basic_ssl_api<ApiTraits>>::type& {
139  return x;
140 }
141 //------------------------------------------------------------------------------
142 } // namespace eagine::sslp
143 
144 #include <eagine/ssl_api.inl>
145 
146 // NOLINTNEXTLINE(cert-dcl58-cpp)
147 namespace std {
148 //------------------------------------------------------------------------------
149 template <typename ApiTraits>
150 struct tuple_size<eagine::sslp::basic_ssl_api<ApiTraits>>
151  : public std::integral_constant<std::size_t, 2> {};
152 
153 template <typename ApiTraits>
154 struct tuple_element<0, eagine::sslp::basic_ssl_api<ApiTraits>> {
155  using type = eagine::sslp::basic_ssl_operations<ApiTraits>;
156 };
157 
158 template <typename ApiTraits>
159 struct tuple_element<1, eagine::sslp::basic_ssl_api<ApiTraits>> {
160  using type = eagine::sslp::basic_ssl_constants<ApiTraits>;
161 };
162 //------------------------------------------------------------------------------
163 } // namespace std
164 
165 #endif // EAGINE_SSL_API_HPP
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
basic_block< false > block
Alias for non-const byte memory span.
Definition: block.hpp:27

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).