Cryptolens Client API for C++
SignatureVerifier_v20190401_to_v20180502.hpp
1 #pragma once
2 
3 #include <string>
4 
5 #include "api.hpp"
6 #include "basic_Error.hpp"
7 #include "Error.hpp"
8 
9 namespace cryptolens_io {
10 
11 namespace internal {
12 
13 namespace {
14 
15 constexpr int INNER_NOT_INITIALIZED = 7623;
16 
17 } // namespace
18 
19 template<typename SignatureVerifier>
21 {
22 public:
23 #ifndef CRYPTOLENS_20190701_ALLOW_IMPLICIT_CONSTRUCTORS
24  explicit
25 #endif
27 
28  void set_modulus_base64(::cryptolens_io::v20180502::basic_Error & e, std::string const& modulus_base64);
29  void set_exponent_base64(::cryptolens_io::v20180502::basic_Error & e, std::string const& exponent_base64);
30  bool verify_message(::cryptolens_io::v20180502::basic_Error & e, std::string const& message, std::string const& signature_base64) const;
31 
32 private:
34  SignatureVerifier verifier_;
35 };
36 
37 template<typename SignatureVerifier>
39 : e_(), verifier_(e_)
40 {}
41 
54 template<typename SignatureVerifier>
55 void
57 {
58  namespace api = ::cryptolens_io::v20180502::api;
59  namespace errors = ::cryptolens_io::v20180502::errors;
60 
61  if (e) { return; }
62  if (e_) {
63  e.set(api::main(), errors::Subsystem::SignatureVerifier, INNER_NOT_INITIALIZED);
64  } else {
65  verifier_.set_modulus_base64(e, modulus_base64);
66  }
67  if (e) { e.set_call(api::main(), errors::Call::SIGNATURE_VERIFIER_SET_MODULUS_BASE64); }
68 }
69 
82 template<typename SignatureVerifier>
83 void
85 {
86  namespace api = ::cryptolens_io::v20180502::api;
87  namespace errors = ::cryptolens_io::v20180502::errors;
88 
89  if (e) { return; }
90  if (e_) {
91  e.set(api::main(), errors::Subsystem::SignatureVerifier, INNER_NOT_INITIALIZED);
92  } else {
93  verifier_.set_exponent_base64(e, exponent_base64);
94  }
95  if (e) { e.set_call(api::main(), errors::Call::SIGNATURE_VERIFIER_SET_EXPONENT_BASE64); }
96 }
97 
101 template<typename SignatureVerifier>
102 bool
105  , std::string const& message
106  , std::string const& signature_base64
107  )
108 const
109 {
110  namespace api = ::cryptolens_io::v20180502::api;
111  namespace errors = ::cryptolens_io::v20180502::errors;
112 
113  if (e) { return false; }
114  if (e_) {
115  e.set(api::main(), errors::Subsystem::SignatureVerifier, INNER_NOT_INITIALIZED);
116  return false;
117  }
118 
119  return verifier_.verify_message(e, message, signature_base64);
120 }
121 
122 } // namespace internal
123 
124 } // namespace cryptolens_io
bool verify_message(::cryptolens_io::v20180502::basic_Error &e, std::string const &message, std::string const &signature_base64) const
Definition: SignatureVerifier_v20190401_to_v20180502.hpp:104
Definition: ActivateError.hpp:5
Definition: basic_Error.hpp:90
void set_exponent_base64(::cryptolens_io::v20180502::basic_Error &e, std::string const &exponent_base64)
Definition: SignatureVerifier_v20190401_to_v20180502.hpp:84
Definition: Error.hpp:9
Definition: SignatureVerifier_v20190401_to_v20180502.hpp:20
void set_modulus_base64(::cryptolens_io::v20180502::basic_Error &e, std::string const &modulus_base64)
Definition: SignatureVerifier_v20190401_to_v20180502.hpp:56