Cryptolens Client API for C++
RawLicenseKey.hpp
1 #pragma once
2 
3 #include <string>
4 
5 #include "imports/std/optional"
6 
7 #include "basic_Error.hpp"
8 #include "base64.hpp"
9 
10 namespace cryptolens_io {
11 
12 namespace v20190401 {
13 
26  ( std::string base64_license
27  , std::string signature
28  , std::string decoded_license
29  )
30  : base64_license_(std::move(base64_license))
31  , signature_(std::move(signature))
32  , license_(std::move(decoded_license))
33  { }
34 
35  std::string base64_license_;
36  std::string signature_;
37  std::string license_;
38 public:
39  std::string const& get_base64_license() const;
40 
41  std::string const& get_signature() const;
42 
43  std::string const& get_license() const;
44 
45  template<typename SignatureVerifier>
46  static
47  optional<RawLicenseKey>
48  make
49  ( basic_Error & e
50  , SignatureVerifier const& verifier
51  , std::string base64_license
52  , std::string signature
53  )
54  {
55  if (e) { return nullopt; }
56 
57  optional<std::string> decoded = ::cryptolens_io::v20190401::internal::b64_decode(base64_license);
58 
59  if (!decoded) {
60  e.set(api::main(), errors::Subsystem::Base64);
61  return nullopt;
62  }
63 
64  if (verifier.verify_message(e, *decoded, signature)) {
65  return make_optional(
67  ( std::move(base64_license)
68  , std::move(signature)
69  , std::move(*decoded)
70  )
71  );
72  } else {
73  return nullopt;
74  }
75  }
76 };
77 
78 } // namespace v20190401
79 
80 namespace v20180502 {
81 
83 
84 } // namespace v20180502
85 
86 namespace latest {
87 
89 
90 } // namespace latest
91 
92 } // namespace cryptolens_io
Definition: ActivateError.hpp:5
Definition: RawLicenseKey.hpp:24
Definition: basic_Error.hpp:90