simplify the chexor function
Replace all that map(operator) nonsense. It changes the error raised on invalid hashes, but we don't handle that anywhere, and it shouldn't ever happen in real life. Change-Id: Ib8cb549fac05e0b2725b4ea295326ac0c5e1f035
This commit is contained in:
parent
d3232d4fc5
commit
0219b08b46
@ -19,7 +19,6 @@ from __future__ import with_statement
|
||||
from contextlib import contextmanager
|
||||
import hashlib
|
||||
import logging
|
||||
import operator
|
||||
import os
|
||||
from uuid import uuid4
|
||||
import sys
|
||||
@ -112,11 +111,8 @@ def chexor(old, name, timestamp):
|
||||
"""
|
||||
if name is None:
|
||||
raise Exception('name is None!')
|
||||
old = old.decode('hex')
|
||||
new = hashlib.md5(('%s-%s' % (name, timestamp)).encode('utf_8')).digest()
|
||||
response = ''.join(
|
||||
map(chr, map(operator.xor, map(ord, old), map(ord, new))))
|
||||
return response.encode('hex')
|
||||
new = hashlib.md5(('%s-%s' % (name, timestamp)).encode('utf8')).hexdigest()
|
||||
return '%032x' % (int(old, 16) ^ int(new, 16))
|
||||
|
||||
|
||||
def get_db_connection(path, timeout=30, okay_to_create=False):
|
||||
|
@ -71,7 +71,7 @@ class TestChexor(unittest.TestCase):
|
||||
'4f2ea31ac14d4273fe32ba08062b21de')
|
||||
|
||||
def test_invalid_old_hash(self):
|
||||
self.assertRaises(TypeError, chexor, 'oldhash', 'name',
|
||||
self.assertRaises(ValueError, chexor, 'oldhash', 'name',
|
||||
normalize_timestamp(1))
|
||||
|
||||
def test_no_name(self):
|
||||
|
Loading…
Reference in New Issue
Block a user