1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-11 23:17:15 +00:00
UTPass/plugins/Pass/jobs/decryptjob.cpp

48 lines
1.2 KiB
C++
Raw Normal View History

2025-01-29 16:42:37 +01:00
#include "decryptjob.h"
2025-02-03 17:48:30 +01:00
#include "qdebug.h"
extern "C" {
#include <rnp/rnp.h>
#include <rnp/rnp_err.h>
}
2025-01-29 16:42:37 +01:00
2025-02-03 17:48:30 +01:00
DecryptJob::DecryptJob(QDir rnp_homedir, QString path):
RnpJob(rnp_homedir),
m_encrypted_file_path(path)
2025-01-29 16:42:37 +01:00
{
this->setObjectName("DecryptJob");
}
void DecryptJob::run()
{
2025-02-03 17:48:30 +01:00
qDebug() << "[DecryptJob] Starting";
2025-02-03 21:46:21 +01:00
this->loadFullKeyring(NULL);
2025-02-03 17:48:30 +01:00
rnp_input_t input = NULL;
rnp_output_t output = NULL;
2025-02-03 21:46:21 +01:00
uint8_t *buf = NULL;
2025-02-03 17:48:30 +01:00
size_t buf_len = 0;
2025-02-03 21:46:21 +01:00
QString data = QString::Null();
2025-02-03 17:48:30 +01:00
auto ret = rnp_input_from_path(&input, this->m_encrypted_file_path.toLocal8Bit().data());
if (ret == RNP_SUCCESS) {
ret = rnp_output_to_memory(&output, 0);
}
if (ret == RNP_SUCCESS) {
ret = rnp_decrypt(this->m_ffi, input, output);
}
if (ret == RNP_SUCCESS) {
ret = rnp_output_memory_get_buf(output, &buf, &buf_len, false);
}
if (ret == RNP_SUCCESS) {
2025-02-04 16:36:00 +01:00
data = QString::fromUtf8((char*)buf, buf_len);
2025-02-03 17:48:30 +01:00
}
rnp_input_destroy(input);
rnp_output_destroy(output);
terminateOnError(ret);
2025-02-03 21:46:21 +01:00
emit resultSuccess(this->m_encrypted_file_path, data);
2025-02-03 17:48:30 +01:00
qDebug() << "[DecryptJob] Finished Successfully ";
2025-01-29 16:42:37 +01:00
}