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:
@@ -172,6 +172,35 @@ const Error GpgMEWorker::SetExpiryTime(const char * keyFpr,
|
|||||||
return e;
|
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
|
* Using a temporary context for key creation. It is altered after secret key
|
||||||
* creation, and subkey creation fails thereafter. This is observational.
|
* creation, and subkey creation fails thereafter. This is observational.
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <gpgme++/gpgsetownertrusteditinteractor.h>
|
#include <gpgme++/gpgsetownertrusteditinteractor.h>
|
||||||
#include <gpgme++/gpgsignkeyeditinteractor.h>
|
#include <gpgme++/gpgsignkeyeditinteractor.h>
|
||||||
#include <gpgme++/gpgsetexpirytimeeditinteractor.h>
|
#include <gpgme++/gpgsetexpirytimeeditinteractor.h>
|
||||||
|
#include <gpgme++/gpgadduserideditinteractor.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "LoopbackPassphraseProvider.h"
|
#include "LoopbackPassphraseProvider.h"
|
||||||
|
|
||||||
@@ -84,6 +85,21 @@ public:
|
|||||||
const Error SetExpiryTime(const char * keyFpr,
|
const Error SetExpiryTime(const char * keyFpr,
|
||||||
const string& passphrase,
|
const string& passphrase,
|
||||||
const string& timeString = "0");
|
const string& timeString = "0");
|
||||||
|
/**
|
||||||
|
* Adds a user identity to a key.
|
||||||
|
* \n 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.
|
||||||
|
* @param keyFpr
|
||||||
|
* @param passphrase
|
||||||
|
* @param name
|
||||||
|
* @param email : string with a valid email format
|
||||||
|
* @param comment
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
const Error AddUserID(const char * keyFpr, const string& passphrase,
|
||||||
|
const string& name, const string& email,
|
||||||
|
const string& comment);
|
||||||
/**
|
/**
|
||||||
* Creates a pair of secret and public keys with the default engine
|
* Creates a pair of secret and public keys with the default engine
|
||||||
* algorithms. Default expiry time is 2 * 365 days.
|
* algorithms. Default expiry time is 2 * 365 days.
|
||||||
@@ -216,5 +232,20 @@ public:
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AddUserIDEditInteractor : public GpgAddUserIDEditInteractor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
AddUserIDEditInteractor()
|
||||||
|
: GpgAddUserIDEditInteractor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~AddUserIDEditInteractor()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* GPGMEWORKER_H */
|
#endif /* GPGMEWORKER_H */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user