Skip to content
Browse files

Make security use stdin

  • Loading branch information...
1 parent 72c5f48 commit aab7ce2ddd3eeff9c3f2363efcd5e8a221be2952 @kylef committed
Showing with 17 additions and 7 deletions.
  1. +17 −7 security.py
View
24 security.py
@@ -4,7 +4,7 @@
class security(Module):
@command(usage='[hash data]', example='sha256 hello world')
- @regex(r'^((?P<algorithm>\S+) (?P<data>.+))?$')
+ @regex(r'^((?P<algorithm>\S+)(?P<data>.+)?)?$')
def hash(self, event, algorithm=None, data=''):
if not algorithm:
if hasattr(hashlib, 'algorithms_available'):
@@ -14,20 +14,30 @@ def hash(self, event, algorithm=None, data=''):
return ', '.join(algorithms)
+ if event.stdin:
+ data = event.stdin
+
try:
return hashlib.new(algorithm, bytes(data, 'utf8')).hexdigest()
except ValueError:
return '{}: Unknown algorithm'.format(algorithm)
@command(description='Encode the input with base64')
- def base64(self, event, line):
- return str(base64.encodestring(bytes(line, 'utf8')), 'utf8')
+ def base64(self, event, data):
+ if event.stdin:
+ data = event.stdin
+ return str(base64.encodestring(bytes(data, 'utf8')), 'utf8')
@command(description='Decode the input with base64')
- def decode64(self, event, line):
- return str(base64.decodestring(bytes(line, 'utf8')), 'utf8')
+ def decode64(self, event, data):
+ if event.stdin:
+ data = event.stdin
+ return str(base64.decodestring(bytes(data, 'utf8')), 'utf8')
@command
- def rot13(self, event, line):
+ def rot13(self, event, data):
+ if event.stdin:
+ data = event.stdin
+
rot13_trans = str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm')
- return line.translate(rot13_trans)
+ return data.translate(rot13_trans)

0 comments on commit aab7ce2

Please sign in to comment.
Something went wrong with that request. Please try again.