diff options
Diffstat (limited to 'src/gpg/GpgGenKeyInfo.cpp')
-rw-r--r-- | src/gpg/GpgGenKeyInfo.cpp | 249 |
1 files changed, 122 insertions, 127 deletions
diff --git a/src/gpg/GpgGenKeyInfo.cpp b/src/gpg/GpgGenKeyInfo.cpp index 69da27e3..f4dc777a 100644 --- a/src/gpg/GpgGenKeyInfo.cpp +++ b/src/gpg/GpgGenKeyInfo.cpp @@ -23,150 +23,145 @@ */ #include "gpg/GpgGenKeyInfo.h" - -const QVector<QString> GenKeyInfo::SupportedKeyAlgo = { - "RSA", - "DSA", - "ED25519" -}; - -const QVector<QString> GenKeyInfo::SupportedSubkeyAlgo = { - "RSA", - "DSA", - "ED25519", - "ELG" -}; - -void GenKeyInfo::setAlgo(const QString &m_algo) { - - qDebug() << "set algo " << m_algo; - - reset_options(); - - if (!this->subKey) { - this->setAllowCertification(true); - } else { - this->setAllowCertification(false); - } - - this->allowChangeCertification = false; - - auto lower_algo = m_algo.toLower(); - - if(lower_algo == "rsa") { - /** - * RSA is the world’s premier asymmetric cryptographic algorithm, - * and is built on the difficulty of factoring extremely large composites. - * GnuPG supports RSA with key sizes of between 1024 and 4096 bits. - */ - suggestMinKeySize = 1024; - suggestMaxKeySize = 4096; - suggestSizeAdditionStep = 1024; - setKeySize(2048); - - } else if (lower_algo == "dsa") { - /** - * Algorithm (DSA) as a government standard for digital signatures. - * Originally, it supported key lengths between 512 and 1024 bits. - * Recently, NIST has declared 512-bit keys obsolete: - * now, DSA is available in 1024, 2048 and 3072-bit lengths. - */ - setAllowEncryption(false); - allowChangeEncryption = false; - - suggestMinKeySize = 1024; - suggestMaxKeySize = 3072; - suggestSizeAdditionStep = 1024; - setKeySize(2048); - - } else if (lower_algo == "ed25519") { - /** - * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths ranging from 1024 to 4096 bits. - */ - - setAllowEncryption(false); - allowChangeEncryption = false; - - suggestMinKeySize = -1; - suggestMaxKeySize = -1; - suggestSizeAdditionStep = -1; - setKeySize(-1); - } else if (lower_algo == "elg") { - /** - * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths ranging from 1024 to 4096 bits. - */ - - setAllowAuthentication(false); - allowChangeAuthentication = false; - - setAllowSigning(false); - allowChangeSigning = false; - - suggestMinKeySize = 1024; - suggestMaxKeySize = 4096; - suggestSizeAdditionStep = 1024; - setKeySize(2048); - } - GenKeyInfo::algo = lower_algo; +#include <string> +#include <vector> + +const std::vector<std::string> GpgFrontend::GenKeyInfo::SupportedKeyAlgo = { + "RSA", "DSA", "ED25519"}; + +const std::vector<std::string> GpgFrontend::GenKeyInfo::SupportedSubkeyAlgo = { + "RSA", "DSA", "ED25519", "ELG"}; + +void GpgFrontend::GenKeyInfo::setAlgo(const std::string &m_algo) { + + qDebug() << "set algo " << m_algo.c_str(); + + reset_options(); + + if (!this->subKey) { + this->setAllowCertification(true); + } else { + this->setAllowCertification(false); + } + + this->allowChangeCertification = false; + + std::string lower_algo; + std::transform(m_algo.begin(), m_algo.end(), lower_algo.begin(), + [](unsigned char c) { return std::tolower(c); }); + + if (lower_algo == "rsa") { + /** + * RSA is the world’s premier asymmetric cryptographic algorithm, + * and is built on the difficulty of factoring extremely large composites. + * GnuPG supports RSA with key sizes of between 1024 and 4096 bits. + */ + suggestMinKeySize = 1024; + suggestMaxKeySize = 4096; + suggestSizeAdditionStep = 1024; + setKeySize(2048); + + } else if (lower_algo == "dsa") { + /** + * Algorithm (DSA) as a government standard for digital signatures. + * Originally, it supported key lengths between 512 and 1024 bits. + * Recently, NIST has declared 512-bit keys obsolete: + * now, DSA is available in 1024, 2048 and 3072-bit lengths. + */ + setAllowEncryption(false); + allowChangeEncryption = false; + + suggestMinKeySize = 1024; + suggestMaxKeySize = 3072; + suggestSizeAdditionStep = 1024; + setKeySize(2048); + + } else if (lower_algo == "ed25519") { + /** + * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths + * ranging from 1024 to 4096 bits. + */ + + setAllowEncryption(false); + allowChangeEncryption = false; + + suggestMinKeySize = -1; + suggestMaxKeySize = -1; + suggestSizeAdditionStep = -1; + setKeySize(-1); + } else if (lower_algo == "elg") { + /** + * GnuPG supports the Elgamal asymmetric encryption algorithm in key lengths + * ranging from 1024 to 4096 bits. + */ + + setAllowAuthentication(false); + allowChangeAuthentication = false; + + setAllowSigning(false); + allowChangeSigning = false; + + suggestMinKeySize = 1024; + suggestMaxKeySize = 4096; + suggestSizeAdditionStep = 1024; + setKeySize(2048); + } + GenKeyInfo::algo = lower_algo; } -void GenKeyInfo::reset_options() { - - allowChangeEncryption = true; - setAllowEncryption(true); - - allowChangeCertification = true; - setAllowCertification(true); +void GpgFrontend::GenKeyInfo::reset_options() { - allowChangeSigning = true; - setAllowSigning(true); + allowChangeEncryption = true; + setAllowEncryption(true); - allowChangeAuthentication = true; - setAllowAuthentication(true); + allowChangeCertification = true; + setAllowCertification(true); + allowChangeSigning = true; + setAllowSigning(true); - passPhrase.clear(); + allowChangeAuthentication = true; + setAllowAuthentication(true); + passPhrase.clear(); } -QString GenKeyInfo::getKeySizeStr() const { - if(keySize > 0) { - return QString::number(keySize); - } - else { - return QString(); - } - +std::string GpgFrontend::GenKeyInfo::getKeySizeStr() const { + if (keySize > 0) { + return std::to_string(keySize); + } else { + return {}; + } } -void GenKeyInfo::setKeySize(int m_key_size) { - if (m_key_size < suggestMinKeySize || m_key_size > suggestMaxKeySize) { - return; - } - GenKeyInfo::keySize = m_key_size; +void GpgFrontend::GenKeyInfo::setKeySize(int m_key_size) { + if (m_key_size < suggestMinKeySize || m_key_size > suggestMaxKeySize) { + return; + } + GenKeyInfo::keySize = m_key_size; } -void GenKeyInfo::setExpired(const QDateTime &m_expired) { - auto current = QDateTime::currentDateTime(); - if (isNonExpired() && m_expired < current.addYears(2)) { - GenKeyInfo::expired = m_expired; - } +void GpgFrontend::GenKeyInfo::setExpired(const QDateTime &m_expired) { + auto current = QDateTime::currentDateTime(); + if (isNonExpired() && m_expired < current.addYears(2)) { + GenKeyInfo::expired = m_expired; + } } -void GenKeyInfo::setNonExpired(bool m_non_expired) { - if (!m_non_expired) { - this->expired = QDateTime(QDateTime::fromTime_t(0)); - } - GenKeyInfo::nonExpired = m_non_expired; +void GpgFrontend::GenKeyInfo::setNonExpired(bool m_non_expired) { + if (!m_non_expired) { + this->expired = QDateTime(QDateTime::fromTime_t(0)); + } + GenKeyInfo::nonExpired = m_non_expired; } -void GenKeyInfo::setAllowEncryption(bool m_allow_encryption) { - if(allowChangeEncryption) - GenKeyInfo::allowEncryption = m_allow_encryption; +void GpgFrontend::GenKeyInfo::setAllowEncryption(bool m_allow_encryption) { + if (allowChangeEncryption) + GenKeyInfo::allowEncryption = m_allow_encryption; } -void GenKeyInfo::setAllowCertification(bool m_allow_certification) { - if(allowChangeCertification) - GenKeyInfo::allowCertification = m_allow_certification; +void GpgFrontend::GenKeyInfo::setAllowCertification( + bool m_allow_certification) { + if (allowChangeCertification) + GenKeyInfo::allowCertification = m_allow_certification; } - |