aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2019-07-28 16:41:12 +0100
committerGravatar jesopo2019-07-28 16:41:12 +0100
commit06b41cb30efa8aadc4a748ff83116cf860e82352 (patch)
tree5d770d40fd640069c197d12d1e1941712c017946
parentRefactor hook kwargs to be stored as a list of tuples to support key duplicates (diff)
signature
Show available hash algorithms when none is provided
-rw-r--r--modules/hash.py18
1 files 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: <algo> <string>
"""
- 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))