aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/utils.cpp')
-rw-r--r--src/cli/utils.cpp232
1 files changed, 0 insertions, 232 deletions
diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp
index c9075e2f8..2de6b0ccb 100644
--- a/src/cli/utils.cpp
+++ b/src/cli/utils.cpp
@@ -8,23 +8,11 @@
#include "cli.h"
#include <botan/version.h>
-#include <botan/rng.h>
#include <botan/cpuid.h>
-#include <botan/hex.h>
-#include <botan/parsing.h>
#include <botan/internal/stl_util.h>
#include <sstream>
-#include <iterator>
#include <iomanip>
-#if defined(BOTAN_HAS_MAC)
- #include <botan/mac.h>
-#endif
-
-#if defined(BOTAN_HAS_BASE64_CODEC)
- #include <botan/base64.h>
-#endif
-
#if defined(BOTAN_HAS_HTTP_UTIL)
#include <botan/http_util.h>
#endif
@@ -261,49 +249,6 @@ class Print_Cpuid final : public Command
BOTAN_REGISTER_COMMAND("cpuid", Print_Cpuid);
-class RNG final : public Command
- {
- public:
- RNG() : Command("rng --system --rdrand --auto --entropy --drbg --drbg-seed= *bytes") {}
-
- std::string group() const override
- {
- return "misc";
- }
-
- std::string description() const override
- {
- return "Sample random bytes from the specified rng";
- }
-
- void go() override
- {
- std::string type = get_arg("rng-type");
-
- if(type.empty())
- {
- for(std::string flag : { "system", "rdrand", "auto", "entropy", "drbg" })
- {
- if(flag_set(flag))
- {
- type = flag;
- break;
- }
- }
- }
-
- const std::string drbg_seed = get_arg("drbg-seed");
- std::unique_ptr<Botan::RandomNumberGenerator> rng = cli_make_rng(type, drbg_seed);
-
- for(const std::string& req : get_arg_list("bytes"))
- {
- output() << Botan::hex_encode(rng->random_vec(Botan::to_u32bit(req))) << "\n";
- }
- }
- };
-
-BOTAN_REGISTER_COMMAND("rng", RNG);
-
#if defined(BOTAN_HAS_HTTP_UTIL)
class HTTP_Get final : public Command
@@ -335,181 +280,4 @@ 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") {}
-
- std::string group() const override
- {
- return "codec";
- }
-
- std::string description() const override
- {
- return "Hex encode a given 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") {}
-
- std::string group() const override
- {
- return "codec";
- }
-
- std::string description() const override
- {
- return "Hex decode a given 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
- {
- public:
- Base64_Encode() : Command("base64_enc file") {}
-
- std::string group() const override
- {
- return "codec";
- }
-
- std::string description() const override
- {
- return "Encode given file to Base64";
- }
-
- void go() override
- {
- auto onData = [&](const uint8_t b[], size_t l)
- {
- output() << Botan::base64_encode(b, l);
- };
- this->read_file(get_arg("file"), onData, 768);
- }
- };
-
-BOTAN_REGISTER_COMMAND("base64_enc", Base64_Encode);
-
-class Base64_Decode final : public Command
- {
- public:
- Base64_Decode() : Command("base64_dec file") {}
-
- std::string group() const override
- {
- return "codec";
- }
-
- std::string description() const override
- {
- return "Decode Base64 encoded file";
- }
-
- void go() override
- {
- auto write_bin = [&](const uint8_t b[], size_t l)
- {
- Botan::secure_vector<uint8_t> bin = Botan::base64_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("base64_dec", Base64_Decode);
-
-#endif // base64
-
-#if defined(BOTAN_HAS_HMAC)
-
-class HMAC final : public Command
- {
- public:
- HMAC() : Command("hmac --hash=SHA-256 --buf-size=4096 --no-fsname key *files") {}
-
- std::string group() const override
- {
- return "hmac";
- }
-
- std::string description() const override
- {
- return "Compute the HMAC tag of given file(s)";
- }
-
- void go() override
- {
- const bool no_fsname = flag_set("no-fsname");
- const std::string hash_algo = get_arg("hash");
- std::unique_ptr<Botan::MessageAuthenticationCode> hmac =
- Botan::MessageAuthenticationCode::create("HMAC(" + hash_algo + ")");
-
- if(!hmac)
- { throw CLI_Error_Unsupported("HMAC", hash_algo); }
-
- hmac->set_key(slurp_file(get_arg("key")));
-
- const size_t buf_size = get_arg_sz("buf-size");
-
- std::vector<std::string> files = get_arg_list("files");
- if(files.empty())
- { files.push_back("-"); } // read stdin if no arguments on command line
-
- for(const std::string& fsname : files)
- {
- try
- {
- auto update_hmac = [&](const uint8_t b[], size_t l) { hmac->update(b, l); };
- read_file(fsname, update_hmac, buf_size);
- output() << Botan::hex_encode(hmac->final());
-
- if(no_fsname == false)
- output() << " " << fsname;
-
- output() << "\n";
- }
- catch(CLI_IO_Error& e)
- {
- error_output() << e.what() << "\n";
- }
- }
- }
- };
-
-BOTAN_REGISTER_COMMAND("hmac", HMAC);
-
-#endif // hmac
-
}