diff options
Diffstat (limited to '')
| -rw-r--r-- | libs/util.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/util.py b/libs/util.py new file mode 100644 index 0000000..abc6ea2 --- /dev/null +++ b/libs/util.py @@ -0,0 +1,26 @@ +from base64 import b64encode +from passlib.hash import bcrypt +import hashlib +import textwrap + + +def base64(text) -> str: + return b64encode(str(text).encode("utf8")).decode("utf8") + + +def sha256(text) -> str: + return hashlib.sha256(str(text).encode("utf-8")).hexdigest() + + +def indent(text: str, prefix: str, predicate=None) -> str: + text = str(text) + + if predicate == "not_first": + first_line = text.splitlines()[0] + predicate = lambda ln: ln.strip() != first_line + + return textwrap.indent(textwrap.dedent(text), prefix, predicate) + + +def hash_bcrypt(secret: str, salt: str) -> str: + return bcrypt.using(salt=str(salt)).hash(str(secret)) |