diff options
author | Jack Lloyd <[email protected]> | 2019-09-23 11:33:53 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-09-23 11:33:53 -0400 |
commit | 9b659f3269393423baaf6546c1130c28b4ae3c38 (patch) | |
tree | 3e5beeef77e9c96919960688cc83301919b8d979 /src/cli/codec.cpp | |
parent | 7c3122ec4275630d78fbdcb03882b7e1fee45c81 (diff) |
Add base32 encoding/decoding util to the cli
Diffstat (limited to 'src/cli/codec.cpp')
-rw-r--r-- | src/cli/codec.cpp | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/cli/codec.cpp b/src/cli/codec.cpp index 0d3df336d..48388d1a7 100644 --- a/src/cli/codec.cpp +++ b/src/cli/codec.cpp @@ -10,6 +10,10 @@ #include <botan/hex.h> #endif +#if defined(BOTAN_HAS_BASE32_CODEC) + #include <botan/base32.h> +#endif + #if defined(BOTAN_HAS_BASE58_CODEC) #include <botan/base58.h> #endif @@ -139,7 +143,67 @@ class Base58_Decode final : public Command BOTAN_REGISTER_COMMAND("base58_dec", Base58_Decode); -#endif // base64 +#endif // base58 + +#if defined(BOTAN_HAS_BASE32_CODEC) + +class Base32_Encode final : public Command + { + public: + Base32_Encode() : Command("base32_enc file") {} + + std::string group() const override + { + return "codec"; + } + + std::string description() const override + { + return "Encode given file to Base32"; + } + + void go() override + { + auto onData = [&](const uint8_t b[], size_t l) + { + output() << Botan::base32_encode(b, l); + }; + this->read_file(get_arg("file"), onData, 768); + } + }; + +BOTAN_REGISTER_COMMAND("base32_enc", Base32_Encode); + +class Base32_Decode final : public Command + { + public: + Base32_Decode() : Command("base32_dec file") {} + + std::string group() const override + { + return "codec"; + } + + std::string description() const override + { + return "Decode Base32 encoded file"; + } + + void go() override + { + auto write_bin = [&](const uint8_t b[], size_t l) + { + Botan::secure_vector<uint8_t> bin = Botan::base32_decode(reinterpret_cast<const char*>(b), l); + output().write(reinterpret_cast<const char*>(bin.data()), bin.size()); + }; + + this->read_file(get_arg("file"), write_bin, 1024); + } + }; + +BOTAN_REGISTER_COMMAND("base32_dec", Base32_Decode); + +#endif // base32 #if defined(BOTAN_HAS_BASE64_CODEC) |