-
Notifications
You must be signed in to change notification settings - Fork 14
/
gpg_helper.hpp
62 lines (47 loc) · 1.38 KB
/
gpg_helper.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _GPG_HELPER_HPP_
#define _GPG_HELPER_HPP_
#include <vector>
#include <thread>
#include <cstdint>
#include <gcrypt.h>
#include "safe_stack.hpp"
#include "error_check.hpp"
#define GCRY_CALL(func, args...) error_wrapper<gcry_error_t>(#func, (func)(args), GPG_ERR_NO_ERROR, gcry_strerror)
class GPGKey {
private:
enum openpgp_pk_algos {
PK_RSA = 1,
PK_ECDH = 18,
PK_ECDSA = 19,
PK_EDDSA = 22,
};
openpgp_pk_algos pk_algo;
uint32_t creation_time;
std::vector<std::vector<uint8_t>> private_params;
std::vector<std::vector<uint8_t>> public_params;
public:
explicit GPGKey(const std::string &algorithm);
GPGKey(const GPGKey&) = delete;
GPGKey& operator=(const GPGKey&) = delete;
GPGKey(GPGKey&&) = default;
GPGKey& operator=(GPGKey&&) = default;
std::vector<uint8_t> load_fpr_hash_packet() const;
std::vector<uint8_t> load_seckey_packet() const;
void set_creation_time(uint32_t timestamp);
};
class GPGWorker {
private:
bool shutdown_flag = false;
std::string algorithm;
std::deque<std::thread> threads;
SafeStack<GPGKey> key_stack;
void worker();
public:
explicit GPGWorker(size_t n_thread, const std::string &algo);
GPGWorker(const GPGWorker&) = delete;
GPGWorker& operator= (const GPGWorker&) = delete;
~GPGWorker();
GPGKey recv_key();
void shutdown();
};
#endif