Add function to add a new user identity to a key.

The email parameter must have a valid email address format here, else
GPGME will refuse to create the identity. This is not the case when
creating a key, where any string is accepted.
This commit is contained in:
SET
2020-11-16 15:58:50 +01:00
parent 4aa4ec9bf3
commit da3f5c3516
2 changed files with 60 additions and 0 deletions

View File

@@ -172,6 +172,35 @@ const Error GpgMEWorker::SetExpiryTime(const char * keyFpr,
return e;
}
const Error GpgMEWorker::AddUserID(const char* keyFpr, const string& passphrase,
const string& name, const string& email,
const string& comment)
{
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);
AddUserIDEditInteractor * interactor = new AddUserIDEditInteractor();
interactor->setNameUtf8(name);
interactor->setEmailUtf8(email);
interactor->setCommentUtf8(comment);
GpgME::Data d;
e = m_ctx->edit(k, std::unique_ptr<AddUserIDEditInteractor> (interactor), d);
m_ctx->clearSigningKeys();
return e;
}
/*
* Using a temporary context for key creation. It is altered after secret key
* creation, and subkey creation fails thereafter. This is observational.