diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/utils.cpp | 32 | ||||
-rwxr-xr-x | src/scripts/test_cli.py | 13 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index 2de6b0ccb..52b14ff1c 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -17,6 +17,10 @@ #include <botan/http_util.h> #endif +#if defined(BOTAN_HAS_UUID) + #include <botan/uuid.h> +#endif + namespace Botan_CLI { class Print_Help final : public Command @@ -249,6 +253,34 @@ class Print_Cpuid final : public Command BOTAN_REGISTER_COMMAND("cpuid", Print_Cpuid); +#if defined(BOTAN_HAS_UUID) + +class Print_UUID final : public Command + { + public: + Print_UUID() : Command("uuid") {} + + std::string group() const override + { + return "misc"; + } + + std::string description() const override + { + return "Print a random UUID"; + } + + void go() override + { + Botan::UUID uuid(rng()); + output() << uuid.to_string() << "\n"; + } + }; + +BOTAN_REGISTER_COMMAND("uuid", Print_UUID); + +#endif + #if defined(BOTAN_HAS_HTTP_UTIL) class HTTP_Get final : public Command diff --git a/src/scripts/test_cli.py b/src/scripts/test_cli.py index 308c4ed53..15776f6f7 100755 --- a/src/scripts/test_cli.py +++ b/src/scripts/test_cli.py @@ -659,6 +659,18 @@ def cli_pk_encrypt_tests(): test_cli("pk_decrypt", [rsa_priv_key, ctext_file, "--output=%s" % (recovered_file)], "") test_cli("hash", ["--no-fsname", "--algo=SHA-256", recovered_file], rng_output_hash) +def cli_uuid_tests(): + fixed_drbg_seed = "802" * 32 + + test_cli("uuid", ['--rng-type=drbg', '--drbg-seed=' + fixed_drbg_seed], "D80F88F6-ADBE-45AC-B10C-3602E67D985B") + + uuid_re = re.compile(r'[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}') + + output = test_cli("uuid", []) + + if uuid_re.match(output) is None: + logging.error('Bad uuid output %s' % (output)) + def cli_tls_client_hello_tests(): # pylint: disable=line-too-long @@ -829,6 +841,7 @@ def main(args=None): cli_tls_socket_tests, cli_trust_root_tests, cli_tss_tests, + cli_uuid_tests, cli_version_tests, ] |