From 06b41cb30efa8aadc4a748ff83116cf860e82352 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 28 Jul 2019 16:41:12 +0100 Subject: [PATCH] Show available hash algorithms when none is provided --- modules/hash.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/hash.py b/modules/hash.py index f3c46d67..2a9d6ce0 100644 --- a/modules/hash.py +++ b/modules/hash.py @@ -4,17 +4,21 @@ import hashlib from src import ModuleManager, utils class Module(ModuleManager.BaseModule): - @utils.hook("received.command.hash", min_args=2, remove_empty=False) + @utils.hook("received.command.hash", remove_empty=False) def hash(self, event): """ :help: Hash a given string with a given algorithm :usage: """ - algorithm = event["args_split"][0].lower() - if algorithm in hashlib.algorithms_available: + if event["args_split"]: + algorithm = event["args_split"][0].lower() phrase = " ".join(event["args_split"][1:]) - cipher_text = hashlib.new(algorithm, phrase.encode("utf8") - ).hexdigest() - event["stdout"].write("%s -> %s" % (phrase, cipher_text)) + if algorithm in hashlib.algorithms_available: + cipher_text = hashlib.new(algorithm, phrase.encode("utf8") + ).hexdigest() + event["stdout"].write("%s -> %s" % (phrase, cipher_text)) + else: + event["stderr"].write("Unknown algorithm provided") else: - event["stderr"].write("Unknown algorithm provided") + event["stdout"].write("Available algorithms: %s" % + ", ".join(hashlib.algorithms_available))