aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils/GpgUtils.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-12-28 06:32:49 +0000
committersaturneric <[email protected]>2023-12-28 06:32:49 +0000
commit300e55bf5bddc393de050c2ca9a0356fce9a8a9d (patch)
tree8332e6b50158718ad98c954302951668a57712a8 /src/core/utils/GpgUtils.cpp
parentfeat: avoid reading entire file to memory (diff)
downloadGpgFrontend-300e55bf5bddc393de050c2ca9a0356fce9a8a9d.tar.gz
GpgFrontend-300e55bf5bddc393de050c2ca9a0356fce9a8a9d.zip
feat: add simple archiving functions for encrypt and decrypt
Diffstat (limited to 'src/core/utils/GpgUtils.cpp')
-rw-r--r--src/core/utils/GpgUtils.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp
index 886dc0fc..20a96e12 100644
--- a/src/core/utils/GpgUtils.cpp
+++ b/src/core/utils/GpgUtils.cpp
@@ -121,4 +121,67 @@ auto TextIsSigned(BypeArrayRef text) -> int {
}
return 0;
}
+
+auto SetExtensionOfOutputFile(std::filesystem::path path, GpgOperation opera,
+ bool ascii) -> std::filesystem::path {
+ std::string extension;
+
+ if (ascii) {
+ switch (opera) {
+ case kENCRYPT:
+ case kSIGN:
+ case kENCRYPT_SIGN:
+ extension += ".asc";
+ break;
+ default:
+ break;
+ }
+ } else {
+ switch (opera) {
+ case kENCRYPT:
+ case kENCRYPT_SIGN:
+ extension += ".gpg";
+ break;
+ case kSIGN:
+ extension = ".sig";
+ break;
+ default:
+ break;
+ }
+ }
+ return path.replace_extension(extension);
+}
+
+auto SetExtensionOfOutputFileForArchive(std::filesystem::path path,
+ GpgOperation opera, bool ascii)
+ -> std::filesystem::path {
+ std::string extension;
+
+ if (ascii) {
+ switch (opera) {
+ case kENCRYPT:
+ case kENCRYPT_SIGN:
+ extension += ".tar.asc";
+ return path.replace_extension(extension);
+ case kDECRYPT:
+ case kDECRYPT_VERIFY:
+ return path.parent_path();
+ default:
+ break;
+ }
+ } else {
+ switch (opera) {
+ case kENCRYPT:
+ case kENCRYPT_SIGN:
+ extension += ".tar.gpg";
+ return path.replace_extension(extension);
+ case kDECRYPT:
+ case kDECRYPT_VERIFY:
+ return path.parent_path();
+ default:
+ break;
+ }
+ }
+}
+
} // namespace GpgFrontend