Virgil Security Crypto library  2.4.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
VirgilOperationDH.h
1 
37 #ifndef VIRGIL_CRYPTO_VIRGIL_DH_H
38 #define VIRGIL_CRYPTO_VIRGIL_DH_H
39 
40 #include "../VirgilByteArray.h"
41 
42 #include <memory>
43 
44 namespace virgil { namespace crypto { inline namespace primitive {
45 
52 private:
53  template<class Impl>
54  struct Model;
55 
56 public:
62  template<class Impl>
63  VirgilOperationDH(Impl impl) : self_(std::make_shared<Model<Impl>>(std::move(impl))) {}
64 
74  const VirgilByteArray& publicKey, const VirgilByteArray& privateKey,
75  const VirgilByteArray& privateKeyPassword = VirgilByteArray()) const {
76  return self_->doCalculate(publicKey, privateKey, privateKeyPassword);
77  }
78 
83 
84 private:
85  struct Concept {
86 
87  virtual VirgilByteArray doCalculate(
88  const VirgilByteArray& publicKey, const VirgilByteArray& privateKey,
89  const VirgilByteArray& privateKeyPassword) const = 0;
90 
91  virtual ~Concept() noexcept = default;
92  };
93 
94  template<class Impl>
95  struct Model : Concept {
96 
97  explicit Model(Impl impl) : impl_(std::move(impl)) {}
98 
99  VirgilByteArray doCalculate(
100  const VirgilByteArray& publicKey, const VirgilByteArray& privateKey,
101  const VirgilByteArray& privateKeyPassword) const override {
102 
103  return impl_.calculate(publicKey, privateKey, privateKeyPassword);
104  }
105 
106  private:
107  Impl impl_;
108  };
109 
110 private:
111  std::shared_ptr<const Concept> self_;
112 };
113 
114 }}}
115 
116 #endif //VIRGIL_CRYPTO_VIRGIL_DH_H
std::vector< unsigned char > VirgilByteArray
This type represents a sequence of bytes.
Definition: VirgilByteArray.h:50
static VirgilOperationDH getDefault()
Return default implementation.
VirgilByteArray calculate(const VirgilByteArray &publicKey, const VirgilByteArray &privateKey, const VirgilByteArray &privateKeyPassword=VirgilByteArray()) const
Compute shared key by using Diffie-Hellman algorithm.
Definition: VirgilOperationDH.h:73
Define proxy interface for the Diffie-Hellman functionality.
Definition: VirgilOperationDH.h:51
VirgilOperationDH(Impl impl)
Captures implementation object.
Definition: VirgilOperationDH.h:63