diff --git a/GpgMEWorker.cpp b/GpgMEWorker.cpp index 114ea2f..437856f 100644 --- a/GpgMEWorker.cpp +++ b/GpgMEWorker.cpp @@ -173,7 +173,7 @@ const Error GpgMEWorker::RevokeKeyCertifications(const char* fprSigningKey, return e; } -const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr, +const Error GpgMEWorker::SetKeyExpiryTime(const char* keyFpr, const char* subkeyFpr, const string& passphrase, ulong expires) @@ -204,38 +204,12 @@ const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr, m_ppp->SetPassphrase(passphrase); m_ctx->setPassphraseProvider(m_ppp); + // setExpire() allows to expire all subkeys at once. Not implemented here. e = m_ctx->setExpire(k, expires, subkey); return e; } -const Error GpgMEWorker::SetExpiryTime(const char * keyFpr, - const string& passphrase, - const string& timeString) -{ - Error e; - Key k = FindKey(keyFpr, e, true); - if (e.code() != 0) - return e; - e = m_ctx->addSigningKey(k); // +++ - if (e.code() != 0) - return e; - - m_ctx->setPinentryMode(Context::PinentryMode::PinentryLoopback); - if (m_ppp == NULL) - m_ppp = new LoopbackPassphraseProvider(); - m_ppp->SetPassphrase(passphrase); - m_ctx->setPassphraseProvider(m_ppp); - - SetExpiryTimeEditInteractor * interactor - = new SetExpiryTimeEditInteractor(timeString); - GpgME::Data d; - e = m_ctx->edit(k, std::unique_ptr (interactor), d); - m_ctx->clearSigningKeys(); - // NB : with a wrong passphrase, e.code() is 0 ! - return e; -} - const Error GpgMEWorker::AddUserID(const char* keyFpr, const string& passphrase, const string& name, const string& email, const string& comment) diff --git a/GpgMEWorker.h b/GpgMEWorker.h index 024a9af..0527304 100644 --- a/GpgMEWorker.h +++ b/GpgMEWorker.h @@ -91,27 +91,19 @@ public: vector& userIDsToRevoke, const string& passphrase); /** - * Sets the expiry time of a single subkey. Requires GPGME >= 1.15.0. - * \n If no subkey is found (wrong fpr), the expiry time of key is set - * instead. + * Sets the expiry time of a single (sub)key. Requires GPGME >= 1.15.0. + * \n If no subkey is found (wrong fpr) or not provided, the expiry time of + * key is set instead. * @param keyFpr * @param subkeyFpr * @param passphrase * @param expires : seconds from now. Use 0 for no expiry. * @return */ - const Error SetSubkeyExpiryTime(const char * keyFpr, + const Error SetKeyExpiryTime(const char * keyFpr, const char * subkeyFpr, const string& passphrase, ulong expires = 63072000); - /** - * Set new expiry time of a secret key. - * @param timeString - * @return - */ - const Error SetExpiryTime(const char * keyFpr, - const string& passphrase, - const string& timeString = "0"); /** * Adds a user identity to a key. * \n The email parameter must have a valid email address format here, else @@ -259,20 +251,6 @@ public: }; -class SetExpiryTimeEditInteractor : public GpgSetExpiryTimeEditInteractor -{ -public: - - SetExpiryTimeEditInteractor(const std::string& timeString = "0") - : GpgSetExpiryTimeEditInteractor(timeString) - { - }; - - virtual ~SetExpiryTimeEditInteractor() - { - }; -}; - class AddUserIDEditInteractor : public GpgAddUserIDEditInteractor { public: diff --git a/KeyEdit.cpp b/KeyEdit.cpp index 0f6f633..62c3c75 100644 --- a/KeyEdit.cpp +++ b/KeyEdit.cpp @@ -204,31 +204,24 @@ void KeyEdit::OnExpiryClicked(WTreeTableNode* subkeyNode, const WString& keyFpr, m_popupExpiryTime = new PopupExpiryTime(lblExpiry, m_owner->m_tmwMessage); m_popupExpiryTime->Create(keyFpr); m_expiryEditedKeyFpr = keyFpr; - m_popupExpiryTime->GetApplyButton()->clicked().connect(this, &KeyEdit::SetExpiryTime); + m_popupExpiryTime->GetApplyButton()->clicked().connect(this, &KeyEdit::SetKeyExpiryTime); } m_popupExpiryTime->SetSubkeyFpr(subkeyFpr); m_popupExpiryTime->show(); } -void KeyEdit::SetExpiryTime() +void KeyEdit::SetKeyExpiryTime() { GpgMEWorker gpgWorker; GpgME::Error e; const WString keyFpr = m_popupExpiryTime->GetKeyFpr(); - const WString subkeyFpr = m_popupExpiryTime->GetSubkeyFpr(); + WString subkeyFpr = m_popupExpiryTime->GetSubkeyFpr(); if (keyFpr == subkeyFpr) - { - e = gpgWorker.SetExpiryTime(keyFpr.toUTF8().c_str(), - m_popupExpiryTime->GetPassphrase(), - m_popupExpiryTime->GetExpiryTime()); - } - else - { - e = gpgWorker.SetSubkeyExpiryTime(keyFpr.toUTF8().c_str(), - subkeyFpr.toUTF8().c_str(), - m_popupExpiryTime->GetPassphrase(), - m_popupExpiryTime->GetExpiry()); - } + subkeyFpr = WString::Empty; + e = gpgWorker.SetKeyExpiryTime(keyFpr.toUTF8().c_str(), + subkeyFpr.toUTF8().c_str(), + m_popupExpiryTime->GetPassphrase(), + m_popupExpiryTime->GetExpiry()); if (e.code() != 0) { m_owner->m_tmwMessage->SetText(TR("SetExpirationTimeFailure")); diff --git a/KeyEdit.h b/KeyEdit.h index 2cca0e4..3973685 100644 --- a/KeyEdit.h +++ b/KeyEdit.h @@ -58,7 +58,7 @@ private: */ void FillOwnerTrustCombo(WComboBox * cmb, bool keyHasSecret); void EditUidValidity(); - void SetExpiryTime(); + void SetKeyExpiryTime(); void AddOrRevokeUid(); /**