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 
40 namespace GpgFrontend {
41 
42 class 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  using KeyGenAlgo = std::pair<std::string, std::string>;
66 
67  public:
73  static const std::vector<KeyGenAlgo> &GetSupportedKeyAlgo();
74 
80  static const std::vector<KeyGenAlgo> &GetSupportedSubkeyAlgo();
81 
87  static const std::vector<KeyGenAlgo> &GetSupportedKeyAlgoStandalone();
88 
94  static const std::vector<KeyGenAlgo> &GetSupportedSubkeyAlgoStandalone();
95 
102  [[nodiscard]] bool IsSubKey() const { return subkey_; }
103 
109  void SetIsSubKey(bool m_sub_key) { GenKeyInfo::subkey_ = m_sub_key; }
110 
116  [[nodiscard]] std::string GetUserid() const {
117  auto uid_format = boost::format("%1%(%2%)<%3%>") % this->name_ %
118  this->comment_ % this->email_;
119  return uid_format.str();
120  }
121 
127  void SetName(const std::string &m_name) { this->name_ = m_name; }
128 
134  void SetEmail(const std::string &m_email) { this->email_ = m_email; }
135 
141  void SetComment(const std::string &m_comment) { this->comment_ = m_comment; }
142 
148  [[nodiscard]] std::string GetName() const { return name_; }
149 
155  [[nodiscard]] std::string GetEmail() const { return email_; }
156 
162  [[nodiscard]] std::string GetComment() const { return comment_; }
163 
169  [[nodiscard]] const std::string &GetAlgo() const { return algo_; }
170 
176  void SetAlgo(const GpgFrontend::GenKeyInfo::KeyGenAlgo &m_algo);
177 
183  [[nodiscard]] std::string GetKeySizeStr() const;
184 
190  [[nodiscard]] int GetKeyLength() const { return key_size_; }
191 
197  void SetKeyLength(int m_key_size);
198 
204  [[nodiscard]] const boost::posix_time::ptime &GetExpireTime() const {
205  return expired_;
206  }
207 
213  void SetExpireTime(const boost::posix_time::ptime &m_expired);
214 
221  [[nodiscard]] bool IsNonExpired() const { return non_expired_; }
222 
228  void SetNonExpired(bool m_non_expired);
229 
236  [[nodiscard]] bool IsNoPassPhrase() const { return this->no_passphrase_; }
237 
243  void SetNonPassPhrase(bool m_non_pass_phrase) {
244  GenKeyInfo::no_passphrase_ = m_non_pass_phrase;
245  }
246 
253  [[nodiscard]] bool IsAllowSigning() const { return allow_signing_; }
254 
261  [[nodiscard]] bool IsAllowNoPassPhrase() const {
262  return allow_no_pass_phrase_;
263  }
264 
270  void SetAllowSigning(bool m_allow_signing) {
271  if (allow_change_signing_) GenKeyInfo::allow_signing_ = m_allow_signing;
272  }
273 
280  [[nodiscard]] bool IsAllowEncryption() const { return allow_encryption_; }
281 
287  void SetAllowEncryption(bool m_allow_encryption);
288 
295  [[nodiscard]] bool IsAllowCertification() const {
296  return allow_certification_;
297  }
298 
304  void SetAllowCertification(bool m_allow_certification);
305 
312  [[nodiscard]] bool IsAllowAuthentication() const {
313  return allow_authentication_;
314  }
315 
321  void SetAllowAuthentication(bool m_allow_authentication) {
322  if (allow_change_authentication_)
323  GenKeyInfo::allow_authentication_ = m_allow_authentication;
324  }
325 
331  [[nodiscard]] const std::string &GetPassPhrase() const { return passphrase_; }
332 
338  void SetPassPhrase(const std::string &m_pass_phrase) {
339  GenKeyInfo::passphrase_ = m_pass_phrase;
340  }
341 
348  [[nodiscard]] bool IsAllowChangeSigning() const {
349  return allow_change_signing_;
350  }
351 
358  [[nodiscard]] bool IsAllowChangeEncryption() const {
359  return allow_change_encryption_;
360  }
361 
368  [[nodiscard]] bool IsAllowChangeCertification() const {
369  return allow_change_certification_;
370  }
371 
378  [[nodiscard]] bool IsAllowChangeAuthentication() const {
379  return allow_change_authentication_;
380  }
381 
387  [[nodiscard]] int GetSuggestMaxKeySize() const {
388  return suggest_max_key_size_;
389  }
390 
396  [[nodiscard]] int GetSuggestMinKeySize() const {
397  return suggest_min_key_size_;
398  }
399 
405  [[nodiscard]] int GetSizeChangeStep() const {
406  return suggest_size_addition_step_;
407  }
408 
409  private:
410  bool allow_encryption_ = true;
411  bool allow_change_encryption_ = true;
412  bool allow_certification_ = true;
413  bool allow_change_certification_ = true;
414  bool allow_authentication_ = true;
415  bool allow_change_authentication_ = true;
416  bool allow_signing_ = true;
417  bool allow_change_signing_ = true;
418 
423  void reset_options();
424 
425  public:
432  explicit GenKeyInfo(bool m_is_sub_key = false, bool m_standalone = false);
433 };
434 
435 } // namespace GpgFrontend
436 
437 #endif // GPGFRONTEND_GPGGENKEYINFO_H
Definition: GpgGenKeyInfo.h:42
bool IsAllowChangeSigning() const
Definition: GpgGenKeyInfo.h:348
int GetSuggestMinKeySize() const
Get the Suggest Min Key Size object.
Definition: GpgGenKeyInfo.h:396
void SetAllowSigning(bool m_allow_signing)
Set the Allow Signing object.
Definition: GpgGenKeyInfo.h:270
bool IsAllowEncryption() const
Definition: GpgGenKeyInfo.h:280
bool IsSubKey() const
Definition: GpgGenKeyInfo.h:102
int GetKeyLength() const
Get the Key Size object.
Definition: GpgGenKeyInfo.h:190
std::string GetUserid() const
Get the Userid object.
Definition: GpgGenKeyInfo.h:116
void SetEmail(const std::string &m_email)
Set the Email object.
Definition: GpgGenKeyInfo.h:134
void SetName(const std::string &m_name)
Set the Name object.
Definition: GpgGenKeyInfo.h:127
const std::string & GetAlgo() const
Get the Algo object.
Definition: GpgGenKeyInfo.h:169
std::string GetEmail() const
Get the Email object.
Definition: GpgGenKeyInfo.h:155
bool IsNoPassPhrase() const
Definition: GpgGenKeyInfo.h:236
void SetNonPassPhrase(bool m_non_pass_phrase)
Set the Non Pass Phrase object.
Definition: GpgGenKeyInfo.h:243
const std::string & GetPassPhrase() const
Get the Pass Phrase object.
Definition: GpgGenKeyInfo.h:331
void SetComment(const std::string &m_comment)
Set the Comment object.
Definition: GpgGenKeyInfo.h:141
bool IsAllowAuthentication() const
Definition: GpgGenKeyInfo.h:312
void SetAllowAuthentication(bool m_allow_authentication)
Set the Allow Authentication object.
Definition: GpgGenKeyInfo.h:321
bool IsAllowChangeAuthentication() const
Definition: GpgGenKeyInfo.h:378
std::string GetComment() const
Get the Comment object.
Definition: GpgGenKeyInfo.h:162
std::string GetName() const
Get the Name object.
Definition: GpgGenKeyInfo.h:148
int GetSizeChangeStep() const
Get the Size Change Step object.
Definition: GpgGenKeyInfo.h:405
const boost::posix_time::ptime & GetExpireTime() const
Get the Expired object.
Definition: GpgGenKeyInfo.h:204
void SetIsSubKey(bool m_sub_key)
Set the Is Sub Key object.
Definition: GpgGenKeyInfo.h:109
bool IsAllowChangeEncryption() const
Definition: GpgGenKeyInfo.h:358
bool IsAllowCertification() const
Definition: GpgGenKeyInfo.h:295
bool IsAllowSigning() const
Definition: GpgGenKeyInfo.h:253
bool IsAllowChangeCertification() const
Definition: GpgGenKeyInfo.h:368
int GetSuggestMaxKeySize() const
Get the Suggest Max Key Size object.
Definition: GpgGenKeyInfo.h:387
bool IsNonExpired() const
Definition: GpgGenKeyInfo.h:221
bool IsAllowNoPassPhrase() const
Definition: GpgGenKeyInfo.h:261
void SetPassPhrase(const std::string &m_pass_phrase)
Set the Pass Phrase object.
Definition: GpgGenKeyInfo.h:338
Definition: CoreCommonUtil.cpp:31