]> git.mar77i.info Git - hublib/blobdiff - hub/utils.py
functioning basic chat app
[hublib] / hub / utils.py
diff --git a/hub/utils.py b/hub/utils.py
new file mode 100644 (file)
index 0000000..c9d955c
--- /dev/null
@@ -0,0 +1,18 @@
+from base64 import urlsafe_b64encode
+from hashlib import sha3_512
+
+
+def scramble(secret, value):
+    h = sha3_512()
+    h.update(f"{secret}{value}".encode())
+    return urlsafe_b64encode(h.digest()).rstrip(b"=").decode("ascii")
+
+
+def get_redis_pass(redis_conf):
+    prefix = "requirepass "
+    with open(redis_conf, "rt") as fh:
+        for line in fh:
+            if not line.startswith(prefix):
+                continue
+            return line[len(prefix) :].rstrip()
+    return None