From d9ac1385950217893be6f0d6fdb3324b8647d16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 24 Oct 2022 12:21:41 +0200 Subject: cpp: Allow setting the curve to use when generating ECC keys lang/cpp/src/gpggencardkeyinteractor.h (class GpgGenCardKeyInteractor): Add enum Curve. Add member function setCurve. lang/cpp/src/gpggencardkeyinteractor.cpp (class GpgGenCardKeyInteractor::Private): Initialize simple members in-class. Add member curve. (GpgGenCardKeyInteractor::~GpgGenCardKeyInteractor): Use default d'tor. (GpgGenCardKeyInteractor::setCurve): New. (GpgGenCardKeyInteractor::action): Return curve defaulting to Curve25519. -- This enables users of this interactor to request the generation of ECC keys with a specific curve as smart card keys. It's up to the user to specify a curve that is actually supported by the smart card. GnuPG-bug-id: 4429 --- lang/cpp/src/gpggencardkeyinteractor.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lang/cpp/src/gpggencardkeyinteractor.cpp') diff --git a/lang/cpp/src/gpggencardkeyinteractor.cpp b/lang/cpp/src/gpggencardkeyinteractor.cpp index 4d90aa0b..a28169ec 100644 --- a/lang/cpp/src/gpggencardkeyinteractor.cpp +++ b/lang/cpp/src/gpggencardkeyinteractor.cpp @@ -36,16 +36,17 @@ using namespace GpgME; class GpgGenCardKeyInteractor::Private { public: - Private() : keysize("2048"), backup(false), algo(RSA) + Private() : keysize("2048") { - } + std::string name, email, backupFileName, expiry, serial, keysize; - bool backup; - Algo algo; + bool backup = false; + Algo algo = RSA; + std::string curve; }; -GpgGenCardKeyInteractor::~GpgGenCardKeyInteractor() {} +GpgGenCardKeyInteractor::~GpgGenCardKeyInteractor() = default; GpgGenCardKeyInteractor::GpgGenCardKeyInteractor(const std::string &serial): d(new Private) @@ -88,6 +89,15 @@ void GpgGenCardKeyInteractor::setAlgo(Algo algo) d->algo = algo; } +void GpgGenCardKeyInteractor::setCurve(Curve curve) +{ + if (curve == DefaultCurve) { + d->curve.clear(); + } else if (curve >= 1 && curve <= LastCurve) { + d->curve = std::to_string(static_cast(curve)); + } +} + namespace GpgGenCardKeyInteractor_Private { enum { @@ -141,7 +151,7 @@ const char *GpgGenCardKeyInteractor::action(Error &err) const case KEY_CURVE1: case KEY_CURVE2: case KEY_CURVE3: - return "1"; // Only cv25519 supported. + return d->curve.empty() ? "1" : d->curve.c_str(); // default is Curve25519 case NAME: return d->name.c_str(); case EMAIL: -- cgit v1.2.3