Allow changing subkey expiry time.
Needs GPGME 1.15.0. Using the same UI for changing expiry time of the primary secret key.
This commit is contained in:
@@ -145,6 +145,42 @@ const Error GpgMEWorker::CertifyKey(const char* fprSigningKey,
|
||||
return e;
|
||||
}
|
||||
|
||||
const Error GpgMEWorker::SetSubkeyExpiryTime(const char* keyFpr,
|
||||
const char* subkeyFpr,
|
||||
const string& passphrase,
|
||||
ulong expires)
|
||||
{
|
||||
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;
|
||||
|
||||
vector<GpgME::Subkey> subkey;
|
||||
for (uint i = 0; i < k.subkeys().size(); i++)
|
||||
{
|
||||
GpgME::Subkey sk = k.subkey(i);
|
||||
if (string(sk.fingerprint()) == string(subkeyFpr))
|
||||
{
|
||||
subkey.push_back(sk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// There should always be at least one subkey (the key itself).
|
||||
|
||||
m_ctx->setPinentryMode(Context::PinentryMode::PinentryLoopback);
|
||||
if (m_ppp == NULL)
|
||||
m_ppp = new LoopbackPassphraseProvider();
|
||||
m_ppp->SetPassphrase(passphrase);
|
||||
m_ctx->setPassphraseProvider(m_ppp);
|
||||
|
||||
e = m_ctx->setExpire(k, expires, subkey);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
const Error GpgMEWorker::SetExpiryTime(const char * keyFpr,
|
||||
const string& passphrase,
|
||||
const string& timeString)
|
||||
@@ -168,7 +204,7 @@ const Error GpgMEWorker::SetExpiryTime(const char * keyFpr,
|
||||
GpgME::Data d;
|
||||
e = m_ctx->edit(k, std::unique_ptr<SetExpiryTimeEditInteractor> (interactor), d);
|
||||
m_ctx->clearSigningKeys();
|
||||
|
||||
// NB : with a wrong passphrase, e.code() is 0 !
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user