Skip to content

Commit 8e9006c

Browse files
committed
Improvements to README.md
1 parent 8d45773 commit 8e9006c

File tree

1 file changed

+52
-33
lines changed

1 file changed

+52
-33
lines changed

README.md

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
On this page, we have outlined several examples of how to get started with the Cryptolens Client API for C++.
44

5-
> **Note**, Cryptolens Client API for C++ currently supports **activation** and **deactivation** methods. Support for more methods is coming soon.
5+
> **Note**, Cryptolens Client API for C++ currently supports a subset of the full Cryptolens Web API. Please contact us (XXX: Add link) if you need something in particular.
66
77
You can find the API documentation here: [https://help.cryptolens.io/api/cpp/](https://help.cryptolens.io/api/cpp/).
88

@@ -70,6 +70,8 @@ Now we can build the example project:
7070
* Set configuration and platform in the same way as when building the library
7171
* Build and run the project.
7272

73+
Instructions for how to add the library to your own project can be found [here](https://help.cryptolens.io/cpp/). XXX: Fix link
74+
7375
## Library overview
7476

7577
This section contains an overview of the standard way to implement the library in an
@@ -78,33 +80,44 @@ application. The first step is to include the appropriate headers:
7880
```cpp
7981
#include <cryptolens/core.hpp>
8082
#include <cryptolens/Error.hpp>
81-
#include <cryptolens/RequestHandler_XXX.hpp>
82-
#include <cryptolens/SignatureVerifier_YYY.hpp>
83+
#include <cryptolens/Configuration_XXX.hpp>
84+
#include <cryptolens/MachineCodeComputer_YYY.hpp>
85+
86+
namespace cryptolens = ::cryptolens_io::v20190401;
8387
```
8488
85-
We currently support the following RequestHandlers and SignatureVerifiers
89+
Besides including headers the above code sets up a namespace alias for the api version of the C++
90+
library we are using.
91+
92+
The `Configuration` class allows for using different libraries for parsing JSON, making HTTPS
93+
requests, performing cryptographic operations as well as minor changes in the behaviour of the
94+
library. We currently support the following `Configurations` and `MachineCodeComputers`:
8695
87-
| RequestHandler | Description |
88-
| ----------------------------- | ----------------------------------------------------- |
89-
| `RequestHandler_curl` | Uses libcurl |
90-
| `RequestHandler_WinHTTP` | Uses the WinHTTP library available as part of Windows |
96+
| Configuration | Description |
97+
| ----------------------------------- | ----------------------------------------------------- |
98+
| `Configuration_Unix` | Good default configuration for Unix-like based systems. Uses ArduinoJson 5, libcurl and OpenSSL. Checks if the license key has expired against the users system time. |
99+
| `Configuration_Unix_IgnoreExpires` | Same as `Configuration_Unix`, but does not check if the license key has expired against the users system time. |
100+
| `Configuration_Windows` | Good default configuration for Windows based systems. Uses ArduinoJson 5, WinHTTP and CryptoAPI. Checks if the license key has expired against the users system time. |
101+
| `Configuration_Windows_IgnoreExpires` | Same as `Configuration_Windows`, but does not check if the license key has expired against the users system time. |
91102
92-
| SignatureVerifier | Description |
93-
| ----------------------------- | ----------------------------------------------- |
94-
| `SignatureVerifier_OpenSSL` | Uses OpenSSL or LibreSSL |
95-
| `SignatureVerifier_CryptoAPI` | Uses the CryptoAPI available as part of Windows |
103+
| MachineCodeComputer | Description |
104+
| ------------------------------- | ----------------------------------------------- |
105+
| `MachineCodeComputer_static` | Does not automatically compute a machine code, instead the machine code is set by calling a function |
96106
97107
The next step is to create and set up a handle class responsible for making requests
98108
to the Cryptolens Web API.
99109
100110
```cpp
101111
using Cryptolens = cryptolens::basic_Cryptolens
102-
<cryptolens::RequestHandler_curl, cryptolens::SignatureVerifier_OpenSSL>;
112+
<cryptolens::Configuration_XXX<cryptolens::MachineCodeComputer_static>>;
103113
104-
Cryptolens cryptolens_handle;
105114
cryptolens::Error e;
115+
Cryptolens cryptolens_handle(e);
116+
106117
cryptolens_handle.signature_verifier.set_modulus_base64(e, "ABCDEFGHI1234");
107118
cryptolens_handle.signature_verifier.set_exponent_base64(e, "ABCD");
119+
120+
cryptolens_handle.machine_code_computer.set_machine_code(e, "289jf2afs3");
108121
```
109122

110123
Here the strings `"ABCDEFGHI1234"` and `"ABCD"` needs to be replaced by your public keys. These
@@ -116,6 +129,8 @@ the following value on the website
116129
<RSAKeyValue><Modulus>ABCDEFGHI1234</Modulus><Exponent>ABCD</Exponent></RSAKeyValue>
117130
```
118131
132+
In this example we set the machine code used to `"289jf2afs3"`.
133+
119134
Now that the handle class has been set up, we can attempt to activate a license key
120135
121136
```cpp
@@ -126,11 +141,9 @@ cryptolens::optional<cryptolens::LicenseKey> license_key =
126141
, // Cryptolens Access Token
127142
"WyI0NjUiLCJBWTBGTlQwZm9WV0FyVnZzMEV1Mm9LOHJmRDZ1SjF0Vk52WTU0VzB2Il0="
128143
, // Product id
129-
"3646"
144+
3646
130145
, // License Key
131146
"MPDWY-PQAOW-FKSCH-SGAAU"
132-
, // Machine Code
133-
"289jf2afs3"
134147
);
135148
136149
if (e) {
@@ -150,8 +163,6 @@ The `activate` method takes several arguments:
150163
https://app.cryptolens.io/Product.
151164
1. The fourth argument is a string containing the license key string, in most cases this will be
152165
input by the user of the application in some application dependent fashion.
153-
1. The last argument is an optional identifier for the device the application is running on, or
154-
something similar.
155166

156167
After the `activate` call we check if an error occurred by converting `e` to bool. If an error
157168
occured this returns true. If an error occurs, the optional containing the `LicenseKey` object
@@ -167,8 +178,8 @@ if (license_key->check()->has_expired(1234567)) {
167178
return 1;
168179
}
169180

170-
if (license_key->check()-has_feature(1)) { std::cout << "Welcome! Pro version enabled!" << std::endl; }
171-
else { std::cout << "Welcome!" << std::endl; }
181+
if (license_key->check()->has_feature(1)) { std::cout << "Welcome! Pro version enabled!" << std::endl; }
182+
else { std::cout << "Welcome!" << std::endl; }
172183
```
173184
174185
@@ -202,22 +213,24 @@ request to the Web API in the future. Thus we can proceed as during online activ
202213
but save the response as a string:
203214

204215
```cpp
205-
Cryptolens cryptolens_handle;
216+
cryptolens::Error e;
217+
Cryptolens cryptolens_handle(e);
218+
206219
cryptolens_handle.signature_verifier.set_modulus_base64(e, "ABCDEFGHI1234");
207220
cryptolens_handle.signature_verifier.set_exponent_base64(e, "ABCD");
208-
...
221+
222+
cryptolens_handle.machine_code_computer.set_machine_code(e, "289jf2afs3");
223+
209224
cryptolens::optional<cryptolens::LicenseKey> license_key =
210-
cryptolens_handle.activate(
225+
cryptolens_handle.activate
211226
( // Object used for reporting if an error occured
212227
e
213228
, // Cryptolens Access Token
214229
"WyI0NjUiLCJBWTBGTlQwZm9WV0FyVnZzMEV1Mm9LOHJmRDZ1SjF0Vk52WTU0VzB2Il0="
215230
, // Product id
216-
"3646"
231+
3646
217232
, // License Key
218233
"MPDWY-PQAOW-FKSCH-SGAAU"
219-
, // Machine Code
220-
"289jf2afs3"
221234
);
222235
if (e) { handle_error(e); return 1; }
223236

@@ -229,10 +242,13 @@ to check the license later when offline, load the string *s* and recover the lic
229242
230243
```cpp
231244
cryptolens::Error e;
232-
Cryptolens cryptolens_handle;
245+
Cryptolens cryptolens_handle(e);
246+
233247
cryptolens_handle.signature_verifier.set_modulus_base64(e, "ABCDEFGHI1234");
234248
cryptolens_handle.signature_verifier.set_exponent_base64(e, "ABCD");
235249
250+
cryptolens_handle.machine_code_computer.set_machine_code(e, "289jf2afs3");
251+
236252
cryptolens::optional<cryptolens::LicenseKey> license_key =
237253
cryptolens_handle.make_license_key(e, s);
238254
if (e) { handle_error(e); return 1; }
@@ -251,13 +267,16 @@ by using the `handle_activate()` function as follows
251267
```cpp
252268
std::string web_api_response; // Some other part of the code creates and populates this object
253269

254-
SignatureVerifier_XXX signature_verifier;
255270
cryptolens::Error e;
256-
signature_verifier.set_modulus_base64(e, "ABCDEFGHI1234");
257-
signature_verifier.set_exponent_base64(e, "ABCD");
271+
Cryptolens cryptolens_handle(e);
258272

259-
cryptolens::optional<cryptolens::LicenseKey> key =
260-
cryptolens::handle_activate(e, signature_verifier, web_api_resonse);
273+
cryptolens_handle.signature_verifier.set_modulus_base64(e, "ABCDEFGHI1234");
274+
cryptolens_handle.signature_verifier.set_exponent_base64(e, "ABCD");
275+
276+
cryptolens_handle.machine_code_computer.set_machine_code(e, "289jf2afs3");
277+
278+
cryptolens::optional<cryptolens::LicenseKey> license_key =
279+
cryptolens_handle.make_license_key(e, web_api_response);
261280
if (e) { handle_error(e); return 1; }
262281
```
263282

0 commit comments

Comments
 (0)