From cb10cffa20702ec3dac50adb5aeeebd6138279b0 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Fri, 31 Dec 2021 09:50:20 +0800 Subject: (core, test): core improved and test gpg key generation 1. Refactor the initialization code of Context. 2. Improve some callback function support. 3. Improve the key deletion function. 4. Modify the key output of some functions. 5. Add test for key generation. 6. Delete all imported keys at the end of the test case. 7. Add setup mode initialization parameters for Context. --- src/gpg/function/GpgKeyOpera.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/gpg/function/GpgKeyOpera.cpp') diff --git a/src/gpg/function/GpgKeyOpera.cpp b/src/gpg/function/GpgKeyOpera.cpp index 4df06875..4cbc1d0a 100644 --- a/src/gpg/function/GpgKeyOpera.cpp +++ b/src/gpg/function/GpgKeyOpera.cpp @@ -47,11 +47,13 @@ void GpgFrontend::GpgKeyOpera::DeleteKeys( for (const auto& tmp : *key_ids) { auto key = GpgKeyGetter::GetInstance().GetKey(tmp); if (key.good()) { - LOG(INFO) << "GpgKeyOpera DeleteKeys Get Key Good"; - err = check_gpg_error(gpgme_op_delete(ctx, gpgme_key_t(key), 1)); + err = check_gpg_error( + gpgme_op_delete_ext(ctx, gpgme_key_t(key), + GPGME_DELETE_ALLOW_SECRET | GPGME_DELETE_FORCE)); assert(gpg_err_code(err) == GPG_ERR_NO_ERROR); - } else - LOG(WARNING) << "GpgKeyOpera DeleteKeys get key failed" << key.fpr(); + } else { + LOG(WARNING) << "GpgKeyOpera DeleteKeys get key failed" << tmp; + } } } @@ -152,8 +154,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( const char* userid = userid_utf8.c_str(); auto algo_utf8 = params->getAlgo() + params->getKeySizeStr(); - LOG(INFO) << "GpgFrontend::GpgKeyOpera::GenerateKey Params" - << params->getAlgo() << params->getKeySizeStr(); + LOG(INFO) << "params" << params->getAlgo() << params->getKeySizeStr(); const char* algo = algo_utf8.c_str(); unsigned long expires = 0; @@ -176,14 +177,12 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( if (params->isNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->isNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - LOG(INFO) << "GpgFrontend::GpgKeyOpera::GenerateKey Args: " << userid - << algo << expires << flags; + LOG(INFO) << "args: " << userid << algo << expires << flags; err = gpgme_op_createkey(ctx, userid, algo, 0, expires, nullptr, flags); } else { std::stringstream ss; - auto param_format = boost::format{ "\n" @@ -203,6 +202,8 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( ss << ""; + DLOG(INFO) << "params" << std::endl << ss.str(); + err = gpgme_op_genkey(ctx, ss.str().c_str(), nullptr, nullptr); } -- cgit v1.2.3