summaryrefslogtreecommitdiff
path: root/searx/webutils.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-12-28 13:44:28 +0100
committerAlexandre Flament <alex@al-f.net>2021-12-28 23:04:06 +0100
commit8f3a7feb47a84344a190ce83e629afde1181f6ae (patch)
tree08866a29d69af2693912e554b7b7dd9baa0e300b /searx/webutils.py
parent7d4834ac4dd708b87187caff8eb59e783e8c2111 (diff)
[mod] implement is_hmac_of() in webutils / close to new_hmac()
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>, Alexandre Flament
Diffstat (limited to 'searx/webutils.py')
-rw-r--r--searx/webutils.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/searx/webutils.py b/searx/webutils.py
index 11a101806..068582858 100644
--- a/searx/webutils.py
+++ b/searx/webutils.py
@@ -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)