Skip to content

Commit 371f6df

Browse files
committed
Start using ResponseParser class
Previously the code for parsing the server responses were part of the core library. Move this code to the previously added ResponseParser class. This makes it possible to in the future give the user of the library an easy way to change which third party libraries are used for parsing server responses.
1 parent 6419557 commit 371f6df

17 files changed

+590
-362
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ project (cryptolens)
44
set (CRYPTOLENS_BUILD_TESTS OFF CACHE BOOL "build tests?")
55
set (CRYPTOLENS_CURL_EMBED_CACERTS OFF CACHE BOOL "embed the ca certs in the library instead of using system default files?")
66

7-
set (SRC "src/ActivateError.cpp" "src/DataObject.cpp" "src/LicenseKey.cpp" "src/LicenseKeyChecker.cpp" "src/LicenseKeyInformation.cpp" "src/MachineCodeComputer_static.cpp" "src/basic_Cryptolens.cpp" "src/basic_SKM.cpp" "third_party/base64_OpenBSD/base64.cpp")
8-
set (LIBS "")
7+
set (SRC "src/ActivateError.cpp" "src/DataObject.cpp" "src/LicenseKey.cpp" "src/LicenseKeyChecker.cpp" "src/LicenseKeyInformation.cpp" "src/MachineCodeComputer_static.cpp" "src/RawLicenseKey.cpp" "src/ResponseParser_ArduinoJson5.cpp" "src/basic_SKM.cpp" "src/cryptolens_internals.cpp" "third_party/base64_OpenBSD/base64.cpp")
8+
set (LIBS "pthread" "dl")
99

1010
find_package(OpenSSL)
1111
if (${OpenSSL_FOUND})

include/cryptolens/Customer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Customer {
2626
, company_name_(std::move(company_name))
2727
, created_(created)
2828
{
29-
// TODO: Check length requirements
29+
// TODO: Check length requirements (does not matter when we are just reading things from the web api)
3030
}
3131

3232
// Returns the customer id

include/cryptolens/DataObject.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class DataObject {
1414
std::string string_value_;
1515
int int_value_;
1616
public:
17-
// TOOD: Use ints with specific sizes...
1817
DataObject
1918
( int id
2019
, std::string name

include/cryptolens/LicenseKeyInformation.hpp

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
#include "imports/std/optional"
77

8-
#include "basic_Error.hpp"
8+
#include "api.hpp"
99
#include "ActivationData.hpp"
10+
#include "basic_Error.hpp"
1011
#include "Customer.hpp"
1112
#include "DataObject.hpp"
1213
#include "RawLicenseKey.hpp"
@@ -32,37 +33,68 @@ class LicenseKeyChecker;
3233
*/
3334
class LicenseKeyInformation {
3435
private:
35-
LicenseKeyInformation() { };
36-
37-
int product_id;
38-
std::uint64_t created;
39-
std::uint64_t expires;
40-
int period;
41-
bool block;
42-
bool trial_activation;
43-
std::uint64_t sign_date;
44-
bool f1;
45-
bool f2;
46-
bool f3;
47-
bool f4;
48-
bool f5;
49-
bool f6;
50-
bool f7;
51-
bool f8;
52-
53-
optional<int> id;
54-
optional<std::string> key;
55-
optional<std::string> notes;
56-
optional<int> global_id;
57-
optional<Customer> customer;
58-
optional<std::vector<ActivationData>> activated_machines;
59-
optional<int> maxnoofmachines;
60-
optional<std::string> allowed_machines;
61-
optional<std::vector<DataObject>> data_objects;
36+
LicenseKeyInformation();
37+
38+
int product_id_;
39+
std::uint64_t created_;
40+
std::uint64_t expires_;
41+
int period_;
42+
bool block_;
43+
bool trial_activation_;
44+
std::uint64_t sign_date_;
45+
bool f1_;
46+
bool f2_;
47+
bool f3_;
48+
bool f4_;
49+
bool f5_;
50+
bool f6_;
51+
bool f7_;
52+
bool f8_;
53+
54+
optional<int> id_;
55+
optional<std::string> key_;
56+
optional<std::string> notes_;
57+
optional<int> global_id_;
58+
optional<Customer> customer_;
59+
optional<std::vector<ActivationData>> activated_machines_;
60+
optional<int> maxnoofmachines_;
61+
optional<std::string> allowed_machines_;
62+
optional<std::vector<DataObject>> data_objects_;
6263
public:
64+
LicenseKeyInformation(
65+
api::internal::main,
66+
int product_id,
67+
std::uint64_t created,
68+
std::uint64_t expires,
69+
int period,
70+
bool block,
71+
bool trial_activation,
72+
std::uint64_t sign_date,
73+
bool f1,
74+
bool f2,
75+
bool f3,
76+
bool f4,
77+
bool f5,
78+
bool f6,
79+
bool f7,
80+
bool f8,
81+
82+
optional<int> id,
83+
optional<std::string> key,
84+
optional<std::string> notes,
85+
optional<int> global_id,
86+
optional<Customer> customer,
87+
optional<std::vector<ActivationData>> activated_machines,
88+
optional<int> maxnoofmachines,
89+
optional<std::string> allowed_machines,
90+
optional<std::vector<DataObject>> data_objects
91+
);
92+
93+
#if 1
6394
static optional<LicenseKeyInformation> make(basic_Error & e, RawLicenseKey const& raw_license_key);
6495
static optional<LicenseKeyInformation> make(basic_Error & e, optional<RawLicenseKey> const& raw_license_key);
6596
static optional<LicenseKeyInformation> make_unsafe(basic_Error & e, std::string const& license_key);
97+
#endif
6698

6799
LicenseKeyChecker check() const;
68100

include/cryptolens/RawLicenseKey.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ class RawLicenseKey {
3636
std::string signature_;
3737
std::string license_;
3838
public:
39-
// TODO: Move methods
40-
std::string const& get_base64_license() const { return base64_license_; }
39+
std::string const& get_base64_license() const;
4140

42-
std::string const& get_signature() const { return signature_; }
41+
std::string const& get_signature() const;
4342

44-
std::string const& get_license() const { return license_; }
43+
std::string const& get_license() const;
4544

4645
template<typename SignatureVerifier>
4746
static

include/cryptolens/RequestHandler_WinHTTP.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace v20180502 {
9494

9595
namespace errors {
9696

97-
//XXX: Add stuff here
97+
namespace RequestHandler_WinHTTP = ::cryptolens_io::v20190401::errors::RequestHandler_WinHTTP;
9898

9999
} // namespace errors
100100

include/cryptolens/RequestHandler_v20190401_to_v20180502.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RequestHandler_v20190401_to_v20180502<RequestHandler>::make_request(::cryptolens
3838

3939
if (e) { return ""; }
4040
if (e_) {
41-
e.set(api::main(), errors::Subsystem::RequestHandler); // XXX: Add stuff here
41+
e.set(api::main(), errors::Subsystem::RequestHandler); // TODO: Add more detailed error code
4242
return "";
4343
}
4444

include/cryptolens/ResponseParser_ArduinoJson5.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
#pragma once
22

3+
#include "imports/std/optional"
4+
5+
#include <utility>
6+
37
#include "basic_Error.hpp"
8+
#include "LicenseKeyInformation.hpp"
9+
#include "RawLicenseKey.hpp"
410

511
namespace cryptolens_io {
612

713
namespace v20190401 {
814

915
class ResponseParser_ArduinoJson5 {
16+
/*
17+
* Note the API of this class is not considered stable. Please contact us if you would like to create
18+
* a custom ResponseParser.
19+
*/
1020
public:
1121
ResponseParser_ArduinoJson5(basic_Error & e) {}
22+
23+
optional<LicenseKeyInformation> make_license_key_information(basic_Error & e, RawLicenseKey const& raw_license_key) const;
24+
optional<LicenseKeyInformation> make_license_key_information(basic_Error & e, optional<RawLicenseKey> const& raw_license_key) const;
25+
optional<LicenseKeyInformation> make_license_key_information_unsafe(basic_Error & e, std::string const& license_key) const;
26+
27+
optional<std::pair<std::string, std::string>> parse_activate_response(basic_Error & e, std::string const& server_response) const;
28+
std::string parse_create_trial_key_response(basic_Error & e, std::string const& server_response) const;
29+
std::string parse_last_message_response(basic_Error & e, std::string const& server_response) const;
1230
};
1331

1432
} // namespace latest

include/cryptolens/api.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ struct main { };
1010

1111
struct experimental_v1 { };
1212

13+
namespace internal {
14+
15+
struct main { };
16+
17+
} // namespace internal
18+
1319
} // namespace api
1420

1521
} // namespace v20190401

0 commit comments

Comments
 (0)