aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/hmac.py
diff options
context:
space:
mode:
authorBonfaceKilz2020-09-17 16:00:08 +0300
committerGitHub2020-09-17 16:00:08 +0300
commit8da6a70916d2cf18e476ab0adf47f802c481205d (patch)
tree8b9a50fd96d3ab1ee3e812e9be01edba1edeb042 /wqflask/utility/hmac.py
parent0ba82e21e4ec8a0364ee22351e130106dd0b53ea (diff)
parent225c360d0a5c57957fe2bc3299108e9b39f12929 (diff)
downloadgenenetwork2-8da6a70916d2cf18e476ab0adf47f802c481205d.tar.gz
Merge pull request #443 from BonfaceKilz/tests/test-auth-and-utf8
Tests/test auth and utf8
Diffstat (limited to 'wqflask/utility/hmac.py')
-rw-r--r--wqflask/utility/hmac.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/wqflask/utility/hmac.py b/wqflask/utility/hmac.py
index b08be97e..fd75803e 100644
--- a/wqflask/utility/hmac.py
+++ b/wqflask/utility/hmac.py
@@ -7,11 +7,11 @@ from flask import url_for
from wqflask import app
+
def hmac_creation(stringy):
"""Helper function to create the actual hmac"""
secret = app.config['SECRET_HMAC_CODE']
-
hmaced = hmac.new(secret, stringy, hashlib.sha1)
hm = hmaced.hexdigest()
# ZS: Leaving the below comment here to ask Pjotr about
@@ -20,10 +20,12 @@ def hmac_creation(stringy):
hm = hm[:20]
return hm
+
def data_hmac(stringy):
- """Takes arbitray data string and appends :hmac so we know data hasn't been tampered with"""
+ """Takes arbitrary data string and appends :hmac so we know data hasn't been tampered with"""
return stringy + ":" + hmac_creation(stringy)
+
def url_for_hmac(endpoint, **values):
"""Like url_for but adds an hmac at the end to insure the url hasn't been tampered with"""
@@ -36,5 +38,6 @@ def url_for_hmac(endpoint, **values):
combiner = "?"
return url + combiner + "hm=" + hm
+
app.jinja_env.globals.update(url_for_hmac=url_for_hmac,
- data_hmac=data_hmac) \ No newline at end of file
+ data_hmac=data_hmac)