diff options
author | Jack Lloyd <[email protected]> | 2017-04-13 14:45:24 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-04-13 14:45:24 -0400 |
commit | 4737338d1810c3a8934d83a2579c3772afe53768 (patch) | |
tree | 70d3e0ca4fe0af80c1ec5b6da3a2daf597fd4a60 /src/cli/utils.cpp | |
parent | 3fba166d1fcc4f9a90dade07a4d6a828372f3baa (diff) |
Add hex encoder/decoder CLI util
Diffstat (limited to 'src/cli/utils.cpp')
-rw-r--r-- | src/cli/utils.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index 33651c7d7..d561f4cdf 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -231,6 +231,43 @@ BOTAN_REGISTER_COMMAND("http_get", HTTP_Get); #endif // http_util +#if defined(BOTAN_HAS_HEX_CODEC) + +class Hex_Encode final : public Command + { + public: + Hex_Encode() : Command("hex_enc file") {} + + void go() override + { + auto hex_enc_f = [&](const uint8_t b[], size_t l) { output() << Botan::hex_encode(b, l); }; + this->read_file(get_arg("file"), hex_enc_f, 2); + } + }; + +BOTAN_REGISTER_COMMAND("hex_enc", Hex_Encode); + +class Hex_Decode final : public Command + { + public: + Hex_Decode() : Command("hex_dec file") {} + + void go() override + { + auto hex_dec_f = [&](const uint8_t b[], size_t l) + { + std::vector<uint8_t> bin = Botan::hex_decode(reinterpret_cast<const char*>(b), l); + output().write(reinterpret_cast<const char*>(bin.data()), bin.size()); + }; + + this->read_file(get_arg("file"), hex_dec_f, 2); + } + }; + +BOTAN_REGISTER_COMMAND("hex_dec", Hex_Decode); + +#endif + #if defined(BOTAN_HAS_BASE64_CODEC) class Base64_Encode final : public Command |