summaryrefslogtreecommitdiff
path: root/searx/utils.py
diff options
context:
space:
mode:
authorrachmadani haryono <rachmadaniHaryono@users.noreply.github.com>2019-07-17 16:09:09 +0800
committerAlexandre Flament <alex@al-f.net>2019-07-17 10:09:09 +0200
commitec88fb8a0f2db0a789349e04caf23e2283daaf13 (patch)
treeecd0d57e62c4eb3f84bc53132b7b0341fa70a082 /searx/utils.py
parent8f44014627ff26019c0ffc01f77394f56dfb7db1 (diff)
[fix] secret_key can be bytes instead of a string (#1602)
Fix #1600 In settings.yml, the secret_key can be written as string or as base64 encoded data using !!binary notation.
Diffstat (limited to 'searx/utils.py')
-rw-r--r--searx/utils.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/searx/utils.py b/searx/utils.py
index dfa22c5f..6619dd0a 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -384,10 +384,17 @@ def load_module(filename, module_dir):
def new_hmac(secret_key, url):
+ try:
+ secret_key_bytes = bytes(secret_key, 'utf-8')
+ except TypeError as err:
+ if isinstance(secret_key, bytes):
+ secret_key_bytes = secret_key
+ else:
+ raise err
if sys.version_info[0] == 2:
return hmac.new(bytes(secret_key), url, hashlib.sha256).hexdigest()
else:
- return hmac.new(bytes(secret_key, 'utf-8'), url, hashlib.sha256).hexdigest()
+ return hmac.new(secret_key_bytes, url, hashlib.sha256).hexdigest()
def to_string(obj):