diff --git a/swift/common/db.py b/swift/common/db.py index 1f70c89285..0c8e7ea3fc 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -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): diff --git a/test/unit/common/test_db.py b/test/unit/common/test_db.py index ce9b1f4df7..e4e3843c9a 100644 --- a/test/unit/common/test_db.py +++ b/test/unit/common/test_db.py @@ -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):