BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
openssl.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <openssl/ec.h>
3 #include <openssl/crypto.h>
4 #include <openssl/dh.h>
5 #include <openssl/evp.h>
6 #include <openssl/conf.h>
7 #include <openssl/err.h>
8 #include <openssl/ecdsa.h>
9 #include <openssl/ecdh.h>
10 #include <openssl/sha.h>
11 #include <openssl/obj_mac.h>
12 
17 namespace fc
18 {
19  class path;
20 
21  template <typename ssl_type>
22  struct ssl_wrapper
23  {
24  ssl_wrapper(ssl_type* obj):obj(obj) {}
25  ssl_wrapper( ssl_wrapper& copy ) = delete;
26  ssl_wrapper& operator=( ssl_wrapper& copy ) = delete;
27 
28  operator ssl_type*() { return obj; }
29  operator const ssl_type*() const { return obj; }
30  ssl_type* operator->() { return obj; }
31  const ssl_type* operator->() const { return obj; }
32 
33  ssl_type* obj;
34  };
35 
36  #define SSL_TYPE_DECL(name, ssl_type) \
37  struct name : public ssl_wrapper<ssl_type> \
38  { \
39  name( ssl_type* obj=nullptr ); \
40  name( name&& move ); \
41  ~name(); \
42  name& operator=( name&& move ); \
43  };
44 
45  SSL_TYPE_DECL(ec_group, EC_GROUP)
46  SSL_TYPE_DECL(ec_point, EC_POINT)
47  SSL_TYPE_DECL(ecdsa_sig, ECDSA_SIG)
48  SSL_TYPE_DECL(bn_ctx, BN_CTX)
49  SSL_TYPE_DECL(evp_cipher_ctx, EVP_CIPHER_CTX)
50  SSL_TYPE_DECL(ssl_dh, DH)
51 
53  struct ssl_bignum : public ssl_wrapper<BIGNUM>
54  {
55  ssl_bignum() : ssl_wrapper(BN_new()) {}
56  ~ssl_bignum() { BN_free(obj); }
57  };
58 
65  void store_configuration_path(const path& filePath);
66  int init_openssl();
67 
68 } // namespace fc
#define SSL_TYPE_DECL(name, ssl_type)
Definition: openssl.hpp:36
ssl_type * operator->()
Definition: openssl.hpp:30
ssl_wrapper(ssl_type *obj)
Definition: openssl.hpp:24
int init_openssl()
Definition: openssl.cpp:61
const ssl_type * operator->() const
Definition: openssl.hpp:31
ssl_type * obj
Definition: openssl.hpp:33
bignum_st BIGNUM
Definition: bigint.hpp:6
void store_configuration_path(const path &filePath)
Definition: openssl.cpp:56
Definition: api.hpp:15
void copy(const path &from, const path &to)
Definition: filesystem.cpp:241
ssl_wrapper & operator=(ssl_wrapper &copy)=delete
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28