mirror of
https://github.com/searxng/searxng.git
synced 2025-07-12 15:59:21 +02:00
[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.
This commit is contained in:
parent
8f44014627
commit
ec88fb8a0f
2 changed files with 22 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue