GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
GpgGenKeyInfo.h
1
29#ifndef GPGFRONTEND_GPGGENKEYINFO_H
30#define GPGFRONTEND_GPGGENKEYINFO_H
31
32#include <boost/date_time.hpp>
33#include <boost/date_time/gregorian/greg_duration_types.hpp>
34#include <boost/format.hpp>
35#include <string>
36#include <vector>
37
38#include "GpgFrontend.h"
39
40namespace GpgFrontend {
41
42class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
43 bool standalone_ = false;
44 bool subkey_ = false;
45 std::string name_;
46 std::string email_;
47 std::string comment_;
48
49 std::string algo_;
50 int key_size_ = 2048;
51 boost::posix_time::ptime expired_ =
52 boost::posix_time::second_clock::local_time() +
53 boost::gregorian::years(2);
54 bool non_expired_ = false;
55
56 bool no_passphrase_ = false;
57 bool allow_no_pass_phrase_ = true;
58
59 int suggest_max_key_size_ = 4096;
60 int suggest_size_addition_step_ = 1024;
61 int suggest_min_key_size_ = 1024;
62
63 std::string passphrase_;
64
65 public:
71 static const std::vector<std::string> &GetSupportedKeyAlgo();
72
78 static const std::vector<std::string> &GetSupportedSubkeyAlgo();
79
85 static const std::vector<std::string> &GetSupportedKeyAlgoStandalone();
86
92 static const std::vector<std::string> &GetSupportedSubkeyAlgoStandalone();
93
100 [[nodiscard]] bool IsSubKey() const { return subkey_; }
101
107 void SetIsSubKey(bool m_sub_key) { GenKeyInfo::subkey_ = m_sub_key; }
108
114 [[nodiscard]] std::string GetUserid() const {
115 auto uid_format = boost::format("%1%(%2%)<%3%>") % this->name_ %
116 this->comment_ % this->email_;
117 return uid_format.str();
118 }
119
125 void SetName(const std::string &m_name) { this->name_ = m_name; }
126
132 void SetEmail(const std::string &m_email) { this->email_ = m_email; }
133
139 void SetComment(const std::string &m_comment) { this->comment_ = m_comment; }
140
146 [[nodiscard]] std::string GetName() const { return name_; }
147
153 [[nodiscard]] std::string GetEmail() const { return email_; }
154
160 [[nodiscard]] std::string GetComment() const { return comment_; }
161
167 [[nodiscard]] const std::string &GetAlgo() const { return algo_; }
168
174 void SetAlgo(const std::string &m_algo);
175
181 [[nodiscard]] std::string GetKeySizeStr() const;
182
188 [[nodiscard]] int GetKeyLength() const { return key_size_; }
189
195 void SetKeyLength(int m_key_size);
196
202 [[nodiscard]] const boost::posix_time::ptime &GetExpireTime() const {
203 return expired_;
204 }
205
211 void SetExpireTime(const boost::posix_time::ptime &m_expired);
212
219 [[nodiscard]] bool IsNonExpired() const { return non_expired_; }
220
226 void SetNonExpired(bool m_non_expired);
227
234 [[nodiscard]] bool IsNoPassPhrase() const { return this->no_passphrase_; }
235
241 void SetNonPassPhrase(bool m_non_pass_phrase) {
242 GenKeyInfo::no_passphrase_ = m_non_pass_phrase;
243 }
244
251 [[nodiscard]] bool IsAllowSigning() const { return allow_signing_; }
252
259 [[nodiscard]] bool IsAllowNoPassPhrase() const {
260 return allow_no_pass_phrase_;
261 }
262
268 void SetAllowSigning(bool m_allow_signing) {
269 if (allow_change_signing_) GenKeyInfo::allow_signing_ = m_allow_signing;
270 }
271
278 [[nodiscard]] bool IsAllowEncryption() const { return allow_encryption_; }
279
285 void SetAllowEncryption(bool m_allow_encryption);
286
293 [[nodiscard]] bool IsAllowCertification() const {
294 return allow_certification_;
295 }
296
302 void SetAllowCertification(bool m_allow_certification);
303
310 [[nodiscard]] bool IsAllowAuthentication() const {
311 return allow_authentication_;
312 }
313
319 void SetAllowAuthentication(bool m_allow_authentication) {
320 if (allow_change_authentication_)
321 GenKeyInfo::allow_authentication_ = m_allow_authentication;
322 }
323
329 [[nodiscard]] const std::string &GetPassPhrase() const { return passphrase_; }
330
336 void SetPassPhrase(const std::string &m_pass_phrase) {
337 GenKeyInfo::passphrase_ = m_pass_phrase;
338 }
339
346 [[nodiscard]] bool IsAllowChangeSigning() const {
347 return allow_change_signing_;
348 }
349
356 [[nodiscard]] bool IsAllowChangeEncryption() const {
357 return allow_change_encryption_;
358 }
359
366 [[nodiscard]] bool IsAllowChangeCertification() const {
367 return allow_change_certification_;
368 }
369
376 [[nodiscard]] bool IsAllowChangeAuthentication() const {
377 return allow_change_authentication_;
378 }
379
385 [[nodiscard]] int GetSuggestMaxKeySize() const {
386 return suggest_max_key_size_;
387 }
388
394 [[nodiscard]] int GetSuggestMinKeySize() const {
395 return suggest_min_key_size_;
396 }
397
403 [[nodiscard]] int GetSizeChangeStep() const {
404 return suggest_size_addition_step_;
405 }
406
407 private:
408 bool allow_encryption_ = true;
409 bool allow_change_encryption_ = true;
410 bool allow_certification_ = true;
411 bool allow_change_certification_ = true;
412 bool allow_authentication_ = true;
413 bool allow_change_authentication_ = true;
414 bool allow_signing_ = true;
415 bool allow_change_signing_ = true;
416
421 void reset_options();
422
423 public:
430 explicit GenKeyInfo(bool m_is_sub_key = false, bool m_standalone = false);
431};
432
433} // namespace GpgFrontend
434
435#endif // GPGFRONTEND_GPGGENKEYINFO_H
Definition: GpgGenKeyInfo.h:42
bool IsAllowChangeSigning() const
Definition: GpgGenKeyInfo.h:346
int GetSuggestMinKeySize() const
Get the Suggest Min Key Size object.
Definition: GpgGenKeyInfo.h:394
void SetAllowSigning(bool m_allow_signing)
Set the Allow Signing object.
Definition: GpgGenKeyInfo.h:268
bool IsAllowEncryption() const
Definition: GpgGenKeyInfo.h:278
bool IsSubKey() const
Definition: GpgGenKeyInfo.h:100
int GetKeyLength() const
Get the Key Size object.
Definition: GpgGenKeyInfo.h:188
std::string GetUserid() const
Get the Userid object.
Definition: GpgGenKeyInfo.h:114
const boost::posix_time::ptime & GetExpireTime() const
Get the Expired object.
Definition: GpgGenKeyInfo.h:202
void SetEmail(const std::string &m_email)
Set the Email object.
Definition: GpgGenKeyInfo.h:132
void SetName(const std::string &m_name)
Set the Name object.
Definition: GpgGenKeyInfo.h:125
std::string GetEmail() const
Get the Email object.
Definition: GpgGenKeyInfo.h:153
const std::string & GetPassPhrase() const
Get the Pass Phrase object.
Definition: GpgGenKeyInfo.h:329
bool IsNoPassPhrase() const
Definition: GpgGenKeyInfo.h:234
void SetNonPassPhrase(bool m_non_pass_phrase)
Set the Non Pass Phrase object.
Definition: GpgGenKeyInfo.h:241
const std::string & GetAlgo() const
Get the Algo object.
Definition: GpgGenKeyInfo.h:167
void SetComment(const std::string &m_comment)
Set the Comment object.
Definition: GpgGenKeyInfo.h:139
bool IsAllowAuthentication() const
Definition: GpgGenKeyInfo.h:310
void SetAllowAuthentication(bool m_allow_authentication)
Set the Allow Authentication object.
Definition: GpgGenKeyInfo.h:319
bool IsAllowChangeAuthentication() const
Definition: GpgGenKeyInfo.h:376
std::string GetComment() const
Get the Comment object.
Definition: GpgGenKeyInfo.h:160
std::string GetName() const
Get the Name object.
Definition: GpgGenKeyInfo.h:146
int GetSizeChangeStep() const
Get the Size Change Step object.
Definition: GpgGenKeyInfo.h:403
void SetIsSubKey(bool m_sub_key)
Set the Is Sub Key object.
Definition: GpgGenKeyInfo.h:107
bool IsAllowChangeEncryption() const
Definition: GpgGenKeyInfo.h:356
bool IsAllowCertification() const
Definition: GpgGenKeyInfo.h:293
bool IsAllowSigning() const
Definition: GpgGenKeyInfo.h:251
bool IsAllowChangeCertification() const
Definition: GpgGenKeyInfo.h:366
int GetSuggestMaxKeySize() const
Get the Suggest Max Key Size object.
Definition: GpgGenKeyInfo.h:385
bool IsNonExpired() const
Definition: GpgGenKeyInfo.h:219
bool IsAllowNoPassPhrase() const
Definition: GpgGenKeyInfo.h:259
void SetPassPhrase(const std::string &m_pass_phrase)
Set the Pass Phrase object.
Definition: GpgGenKeyInfo.h:336
Definition: CoreCommonUtil.cpp:29