mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +00:00
[mod] implement is_hmac_of() in webutils / close to new_hmac()
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>, Alexandre Flament
This commit is contained in:
committed by
Alexandre Flament
parent
7d4834ac4d
commit
8f3a7feb47
@@ -80,6 +80,11 @@ def new_hmac(secret_key, url):
|
||||
return hmac.new(secret_key.encode(), url, hashlib.sha256).hexdigest()
|
||||
|
||||
|
||||
def is_hmac_of(secret_key, value, hmac_to_check):
|
||||
hmac_of_value = new_hmac(secret_key, value)
|
||||
return len(hmac_of_value) == len(hmac_to_check) and hmac.compare_digest(hmac_of_value, hmac_to_check)
|
||||
|
||||
|
||||
def prettify_url(url, max_length=74):
|
||||
if len(url) > max_length:
|
||||
chunk_len = int(max_length / 2 + 1)
|
||||
|
||||
Reference in New Issue
Block a user