diff options
Diffstat (limited to 'src/gpg/function/GpgKeyImportExporter.cpp')
-rw-r--r-- | src/gpg/function/GpgKeyImportExporter.cpp | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/gpg/function/GpgKeyImportExporter.cpp b/src/gpg/function/GpgKeyImportExporter.cpp index 33f865a7..dd027eab 100644 --- a/src/gpg/function/GpgKeyImportExporter.cpp +++ b/src/gpg/function/GpgKeyImportExporter.cpp @@ -25,6 +25,7 @@ #include "gpg/function/GpgKeyImportExporter.h" #include "GpgConstants.h" +#include "gpg/function/GpgKeyGetter.h" /** * Import key pair @@ -65,30 +66,32 @@ bool GpgFrontend::GpgKeyImportExporter::ExportKeys(KeyIdArgsListPtr& uid_list, bool secret) const { if (uid_list->empty()) return false; - std::stringstream ss; - int _mode = 0; - if (secret) _mode |= GPGME_EXPORT_MODE_SECRET; - // Alleviate another crash problem caused by an unknown array out-of-bounds - // access - auto all_success = true; - for (size_t i = 0; i < uid_list->size(); i++) { - GpgData data_out; - auto err = gpgme_op_export(ctx, (*uid_list)[i].c_str(), _mode, data_out); - if (gpgme_err_code(err) != GPG_ERR_NO_ERROR) all_success = false; - DLOG(INFO) << "exportKeys read_bytes" - << gpgme_data_seek(data_out, 0, SEEK_END); - - auto temp_out_buffer = data_out.Read2Buffer(); + auto keys = GpgKeyGetter::GetInstance().GetKeys(uid_list); + auto keys_array = new gpgme_key_t[keys->size() + 1]; - ss << *temp_out_buffer << std::endl; + int index = 0; + for (const auto& key : *keys) { + keys_array[index++] = gpgme_key_t(key); } + keys_array[index] = nullptr; + + GpgData data_out; + auto err = gpgme_op_export_keys(ctx, keys_array, _mode, data_out); + if (gpgme_err_code(err) != GPG_ERR_NO_ERROR) return false; + + delete[] keys_array; + + DLOG(INFO) << "exportKeys read_bytes" + << gpgme_data_seek(data_out, 0, SEEK_END); + + auto temp_out_buffer = data_out.Read2Buffer(); - out_buffer = std::make_unique<ByteArray>(ss.str()); + swap(temp_out_buffer, out_buffer); - return all_success; + return true; } /** |