Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/signing.py

Issue 5177883412660224: Issue 2234 - Add a WSGI controller to collect email addresses for the Adblock Browser iOS launch (Closed)
Patch Set: Renamed files Created April 23, 2015, 2:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 import hmac
2 import hashlib
3
4 from sitescripts.utils import get_config
5
6 _SECRET = get_config().get('DEFAULT', 'secret')
7
8 def constant_time_compare(s1, s2):
9 if len(s1) != len(s2):
10 return False
11 return reduce(lambda a, b: a | b, (ord(c1) ^ ord(c2) for c1, c2 in zip(s1, s2) )) == 0
12
13 def sign(data):
14 return hmac.new(_SECRET, data, hashlib.sha1).hexdigest()
15
16 def verify(data, signature):
17 return constant_time_compare(sign(data), signature)
OLDNEW

Powered by Google App Engine
This is Rietveld