Use standard binascii

One of the local functions was reimplementing hexlify. Unfortunately
it was also not py3 compatible.

Change-Id: Ib653c960de4dd7494a193525b7b80281616f3007
This commit is contained in:
Stanisław Pitucha 2015-06-23 12:05:49 +10:00
parent fa482a725b
commit fa865402ae
2 changed files with 4 additions and 9 deletions

View File

@ -15,6 +15,8 @@ from __future__ import absolute_import
from cryptography.hazmat.backends.openssl import backend
import binascii
class MessageDigestError(Exception):
def __init__(self, what):
@ -67,13 +69,6 @@ class MessageDigest(object):
self._lib.EVP_MD_CTX_cleanup(self.ctx)
self._lib.EVP_MD_CTX_destroy(self.ctx)
def _octx_to_num(self, x):
v = 0L
lx = len(x)
for i in range(lx):
v = v + ord(x[i]) * (256L ** (lx - i - 1))
return v
def update(self, data):
"""Add more data to the digest."""
@ -95,4 +90,4 @@ class MessageDigest(object):
raise MessageDigestError(
"Failed to get message digest.") # pragma: no cover
digest = self._ffi.string(data)
return hex(self._octx_to_num(digest))[2:-1].upper()
return binascii.hexlify(digest).decode('ascii').upper()

View File

@ -20,7 +20,7 @@ from anchor.X509 import message_digest
class TestMessageDigest(unittest.TestCase):
data = "this is test data to test with"
data = b"this is test data to test with"
def setUp(self):
super(TestMessageDigest, self).setUp()