aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils/IOUtils.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-12-23 17:36:40 +0000
committersaturneric <[email protected]>2023-12-23 17:36:40 +0000
commit956c5ed3a8931bcbfa07fbe2b1af8090188b822b (patch)
tree18ff59a410e2c87d53a05e5483549fb977ec3ddd /src/core/utils/IOUtils.cpp
parentfix: solve all issues of test cases on macos m1 (diff)
downloadGpgFrontend-956c5ed3a8931bcbfa07fbe2b1af8090188b822b.tar.gz
GpgFrontend-956c5ed3a8931bcbfa07fbe2b1af8090188b822b.zip
feat: improve core interfaces of encrypt and decrypt
Diffstat (limited to 'src/core/utils/IOUtils.cpp')
-rw-r--r--src/core/utils/IOUtils.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/utils/IOUtils.cpp b/src/core/utils/IOUtils.cpp
index 5d0a2a54..e0849a5f 100644
--- a/src/core/utils/IOUtils.cpp
+++ b/src/core/utils/IOUtils.cpp
@@ -70,12 +70,34 @@ auto ReadFileStd(const std::filesystem::path& file_name, std::string& data)
return res;
}
+auto GPGFRONTEND_CORE_EXPORT ReadFileGFBuffer(
+ const std::filesystem::path& file_name) -> std::tuple<bool, GFBuffer> {
+ QByteArray byte_data;
+#ifdef WINDOWS
+ const bool res = ReadFile(
+ QString::fromStdU16String(file_name.u16string()).toUtf8(), byte_data);
+#else
+ const bool res = ReadFile(
+ QString::fromStdString(file_name.u8string()).toUtf8(), byte_data);
+#endif
+
+ return {res, GFBuffer(byte_data)};
+}
+
auto WriteFileStd(const std::filesystem::path& file_name,
const std::string& data) -> bool {
return WriteFile(QString::fromStdString(file_name.u8string()).toUtf8(),
QByteArray::fromStdString(data));
}
+auto GPGFRONTEND_CORE_EXPORT WriteFileGFBuffer(
+ const std::filesystem::path& file_name, GFBuffer data) -> bool {
+ return WriteFile(
+ QString::fromStdString(file_name.u8string()).toUtf8(),
+ QByteArray::fromRawData(reinterpret_cast<const char*>(data.Data()),
+ static_cast<qsizetype>(data.Size())));
+}
+
auto CalculateHash(const std::filesystem::path& file_path) -> std::string {
// Returns empty QByteArray() on failure.
QFileInfo info(QString::fromStdString(file_path.string()));