GpgGenKeyInfo.h
#ifndef GPGFRONTEND_GPGGENKEYINFO_H
#define GPGFRONTEND_GPGGENKEYINFO_H
#include <boost/date_time.hpp>
#include <boost/date_time/gregorian/greg_duration_types.hpp>
#include <boost/format.hpp>
#include <string>
#include <vector>
#include "GpgFrontend.h"
namespace GpgFrontend {
class GPGFRONTEND_CORE_EXPORT GenKeyInfo {
bool standalone_ = false;
bool subkey_ = false;
std::string name_;
std::string email_;
std::string comment_;
std::string algo_;
int key_size_ = 2048;
boost::posix_time::ptime expired_ =
boost::posix_time::second_clock::local_time() +
boost::gregorian::years(2);
bool non_expired_ = false;
bool no_passphrase_ = false;
bool allow_no_pass_phrase_ = true;
int suggest_max_key_size_ = 4096;
int suggest_size_addition_step_ = 1024;
int suggest_min_key_size_ = 1024;
std::string passphrase_;
public:
static const std::vector<std::string> &GetSupportedKeyAlgo();
static const std::vector<std::string> &GetSupportedSubkeyAlgo();
static const std::vector<std::string> &GetSupportedKeyAlgoStandalone();
static const std::vector<std::string> &GetSupportedSubkeyAlgoStandalone();
[[nodiscard]] bool IsSubKey() const { return subkey_; }
void SetIsSubKey(bool m_sub_key) { GenKeyInfo::subkey_ = m_sub_key; }
[[nodiscard]] std::string GetUserid() const {
auto uid_format = boost::format("%1%(%2%)<%3%>") % this->name_ %
this->comment_ % this->email_;
return uid_format.str();
}
void SetName(const std::string &m_name) { this->name_ = m_name; }
void SetEmail(const std::string &m_email) { this->email_ = m_email; }
void SetComment(const std::string &m_comment) { this->comment_ = m_comment; }
[[nodiscard]] std::string GetName() const { return name_; }
[[nodiscard]] std::string GetEmail() const { return email_; }
[[nodiscard]] std::string GetComment() const { return comment_; }
[[nodiscard]] const std::string &GetAlgo() const { return algo_; }
void SetAlgo(const std::string &m_algo);
[[nodiscard]] std::string GetKeySizeStr() const;
[[nodiscard]] int GetKeyLength() const { return key_size_; }
void SetKeyLength(int m_key_size);
[[nodiscard]] const boost::posix_time::ptime &GetExpireTime() const {
return expired_;
}
void SetExpireTime(const boost::posix_time::ptime &m_expired);
[[nodiscard]] bool IsNonExpired() const { return non_expired_; }
void SetNonExpired(bool m_non_expired);
[[nodiscard]] bool IsNoPassPhrase() const { return this->no_passphrase_; }
void SetNonPassPhrase(bool m_non_pass_phrase) {
GenKeyInfo::no_passphrase_ = m_non_pass_phrase;
}
[[nodiscard]] bool IsAllowSigning() const { return allow_signing_; }
[[nodiscard]] bool IsAllowNoPassPhrase() const {
return allow_no_pass_phrase_;
}
void SetAllowSigning(bool m_allow_signing) {
if (allow_change_signing_) GenKeyInfo::allow_signing_ = m_allow_signing;
}
[[nodiscard]] bool IsAllowEncryption() const { return allow_encryption_; }
void SetAllowEncryption(bool m_allow_encryption);
[[nodiscard]] bool IsAllowCertification() const {
return allow_certification_;
}
void SetAllowCertification(bool m_allow_certification);
[[nodiscard]] bool IsAllowAuthentication() const {
return allow_authentication_;
}
void SetAllowAuthentication(bool m_allow_authentication) {
if (allow_change_authentication_)
GenKeyInfo::allow_authentication_ = m_allow_authentication;
}
[[nodiscard]] const std::string &GetPassPhrase() const { return passphrase_; }
void SetPassPhrase(const std::string &m_pass_phrase) {
GenKeyInfo::passphrase_ = m_pass_phrase;
}
[[nodiscard]] bool IsAllowChangeSigning() const {
return allow_change_signing_;
}
[[nodiscard]] bool IsAllowChangeEncryption() const {
return allow_change_encryption_;
}
[[nodiscard]] bool IsAllowChangeCertification() const {
return allow_change_certification_;
}
[[nodiscard]] bool IsAllowChangeAuthentication() const {
return allow_change_authentication_;
}
[[nodiscard]] int GetSuggestMaxKeySize() const {
return suggest_max_key_size_;
}
[[nodiscard]] int GetSuggestMinKeySize() const {
return suggest_min_key_size_;
}
[[nodiscard]] int GetSizeChangeStep() const {
return suggest_size_addition_step_;
}
private:
bool allow_encryption_ = true;
bool allow_change_encryption_ = true;
bool allow_certification_ = true;
bool allow_change_certification_ = true;
bool allow_authentication_ = true;
bool allow_change_authentication_ = true;
bool allow_signing_ = true;
bool allow_change_signing_ = true;
void reset_options();
public:
explicit GenKeyInfo(bool m_is_sub_key = false, bool m_standalone = false);
};
} // namespace GpgFrontend
#endif // GPGFRONTEND_GPGGENKEYINFO_H
GpgFrontend::GenKeyInfo::IsAllowChangeAuthentication
bool IsAllowChangeAuthentication() const
Definition: GpgGenKeyInfo.h:376
GpgFrontend::GenKeyInfo::GetUserid
std::string GetUserid() const
Get the Userid object.
Definition: GpgGenKeyInfo.h:114
GpgFrontend::GenKeyInfo::IsAllowNoPassPhrase
bool IsAllowNoPassPhrase() const
Definition: GpgGenKeyInfo.h:259
GpgFrontend::GenKeyInfo::IsAllowAuthentication
bool IsAllowAuthentication() const
Definition: GpgGenKeyInfo.h:310
GpgFrontend::GenKeyInfo::IsAllowChangeEncryption
bool IsAllowChangeEncryption() const
Definition: GpgGenKeyInfo.h:356
GpgFrontend::GenKeyInfo::GetSizeChangeStep
int GetSizeChangeStep() const
Get the Size Change Step object.
Definition: GpgGenKeyInfo.h:403
GpgFrontend::GenKeyInfo::GetSupportedSubkeyAlgo
static const std::vector< std::string > & GetSupportedSubkeyAlgo()
Get the Supported Subkey Algo object.
Definition: GpgGenKeyInfo.cpp:207
GpgFrontend::GenKeyInfo::GetAlgo
const std::string & GetAlgo() const
Get the Algo object.
Definition: GpgGenKeyInfo.h:167
GpgFrontend
Definition: CoreCommonUtil.cpp:29
GpgFrontend::GenKeyInfo::SetAllowSigning
void SetAllowSigning(bool m_allow_signing)
Set the Allow Signing object.
Definition: GpgGenKeyInfo.h:268
GpgFrontend::GenKeyInfo::GetSuggestMaxKeySize
int GetSuggestMaxKeySize() const
Get the Suggest Max Key Size object.
Definition: GpgGenKeyInfo.h:385
GpgFrontend::GenKeyInfo::SetNonPassPhrase
void SetNonPassPhrase(bool m_non_pass_phrase)
Set the Non Pass Phrase object.
Definition: GpgGenKeyInfo.h:241
GpgFrontend::GenKeyInfo::GetKeyLength
int GetKeyLength() const
Get the Key Size object.
Definition: GpgGenKeyInfo.h:188
GpgFrontend::GenKeyInfo::SetAllowCertification
void SetAllowCertification(bool m_allow_certification)
Set the Allow Certification object.
Definition: GpgGenKeyInfo.cpp:189
GpgFrontend::GenKeyInfo::IsNoPassPhrase
bool IsNoPassPhrase() const
Definition: GpgGenKeyInfo.h:234
GpgFrontend::GenKeyInfo::GetName
std::string GetName() const
Get the Name object.
Definition: GpgGenKeyInfo.h:146
GpgFrontend::GenKeyInfo::SetAllowAuthentication
void SetAllowAuthentication(bool m_allow_authentication)
Set the Allow Authentication object.
Definition: GpgGenKeyInfo.h:319
GpgFrontend::GenKeyInfo::SetPassPhrase
void SetPassPhrase(const std::string &m_pass_phrase)
Set the Pass Phrase object.
Definition: GpgGenKeyInfo.h:336
GpgFrontend::GenKeyInfo::IsNonExpired
bool IsNonExpired() const
Definition: GpgGenKeyInfo.h:219
GpgFrontend::GenKeyInfo::IsAllowCertification
bool IsAllowCertification() const
Definition: GpgGenKeyInfo.h:293
GpgFrontend::GenKeyInfo::SetComment
void SetComment(const std::string &m_comment)
Set the Comment object.
Definition: GpgGenKeyInfo.h:139
GpgFrontend::GenKeyInfo::GetSupportedSubkeyAlgoStandalone
static const std::vector< std::string > & GetSupportedSubkeyAlgoStandalone()
Get the Supported Subkey Algo Standalone object.
Definition: GpgGenKeyInfo.cpp:221
GpgFrontend::GenKeyInfo::SetAllowEncryption
void SetAllowEncryption(bool m_allow_encryption)
Set the Allow Encryption object.
Definition: GpgGenKeyInfo.cpp:184
GpgFrontend::GenKeyInfo::SetKeyLength
void SetKeyLength(int m_key_size)
Set the Key Size object.
Definition: GpgGenKeyInfo.cpp:162
GpgFrontend::GenKeyInfo::IsAllowChangeSigning
bool IsAllowChangeSigning() const
Definition: GpgGenKeyInfo.h:346
GpgFrontend::GenKeyInfo::SetEmail
void SetEmail(const std::string &m_email)
Set the Email object.
Definition: GpgGenKeyInfo.h:132
GpgFrontend::GenKeyInfo::GetSuggestMinKeySize
int GetSuggestMinKeySize() const
Get the Suggest Min Key Size object.
Definition: GpgGenKeyInfo.h:394
GpgFrontend::GenKeyInfo::SetExpireTime
void SetExpireTime(const boost::posix_time::ptime &m_expired)
Set the Expired object.
Definition: GpgGenKeyInfo.cpp:170
GpgFrontend::GenKeyInfo::GetSupportedKeyAlgoStandalone
static const std::vector< std::string > & GetSupportedKeyAlgoStandalone()
Get the Supported Key Algo Standalone object.
Definition: GpgGenKeyInfo.cpp:214
GpgFrontend::GenKeyInfo::IsAllowSigning
bool IsAllowSigning() const
Definition: GpgGenKeyInfo.h:251
GpgFrontend::GenKeyInfo::SetIsSubKey
void SetIsSubKey(bool m_sub_key)
Set the Is Sub Key object.
Definition: GpgGenKeyInfo.h:107
GpgFrontend::GenKeyInfo::GetKeySizeStr
std::string GetKeySizeStr() const
Get the Key Size Str object.
Definition: GpgGenKeyInfo.cpp:154
GpgFrontend::GenKeyInfo::IsSubKey
bool IsSubKey() const
Definition: GpgGenKeyInfo.h:100
GpgFrontend::GenKeyInfo::IsAllowChangeCertification
bool IsAllowChangeCertification() const
Definition: GpgGenKeyInfo.h:366
GpgFrontend::GenKeyInfo::GetSupportedKeyAlgo
static const std::vector< std::string > & GetSupportedKeyAlgo()
Get the Supported Key Algo object.
Definition: GpgGenKeyInfo.cpp:200
GpgFrontend::GenKeyInfo::SetName
void SetName(const std::string &m_name)
Set the Name object.
Definition: GpgGenKeyInfo.h:125
GpgFrontend::GenKeyInfo::SetNonExpired
void SetNonExpired(bool m_non_expired)
Set the Non Expired object.
Definition: GpgGenKeyInfo.cpp:178
GpgFrontend::GenKeyInfo::GetEmail
std::string GetEmail() const
Get the Email object.
Definition: GpgGenKeyInfo.h:153
GpgFrontend::GenKeyInfo::GetExpireTime
const boost::posix_time::ptime & GetExpireTime() const
Get the Expired object.
Definition: GpgGenKeyInfo.h:202
GpgFrontend::GenKeyInfo::GenKeyInfo
GenKeyInfo(bool m_is_sub_key=false, bool m_standalone=false)
Construct a new Gen Key Info object.
Definition: GpgGenKeyInfo.cpp:195
GpgFrontend::GenKeyInfo::GetPassPhrase
const std::string & GetPassPhrase() const
Get the Pass Phrase object.
Definition: GpgGenKeyInfo.h:329
GpgFrontend::GenKeyInfo::GetComment
std::string GetComment() const
Get the Comment object.
Definition: GpgGenKeyInfo.h:160
GpgFrontend::GenKeyInfo
Definition: GpgGenKeyInfo.h:42
GpgFrontend::GenKeyInfo::SetAlgo
void SetAlgo(const std::string &m_algo)
Set the Algo object.
Definition: GpgGenKeyInfo.cpp:37
GpgFrontend::GenKeyInfo::IsAllowEncryption
bool IsAllowEncryption() const
Definition: GpgGenKeyInfo.h:278