diff options
author | saturneric <[email protected]> | 2023-12-28 06:32:49 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-12-28 06:32:49 +0000 |
commit | 300e55bf5bddc393de050c2ca9a0356fce9a8a9d (patch) | |
tree | 8332e6b50158718ad98c954302951668a57712a8 /src/core/utils/GpgUtils.cpp | |
parent | feat: avoid reading entire file to memory (diff) | |
download | GpgFrontend-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.cpp | 63 |
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 |