Skip to content

Commit 47fd184

Browse files
committed
hexdigest() should return a string object not bytes
For consistency with the hashlib module in the standard library. Fixes #6.
1 parent 5ddc19f commit 47fd184

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

docs/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ methods provided by the hash objects in the standard library
8181

8282
.. method:: hash.hexdigest()
8383

84-
Like :meth:`digest` except the digest is returned as a bytes object
84+
Like :meth:`digest` except the digest is returned as a string object
8585
of double length, containing only hexadecimal digits.
8686

8787
.. method:: hash.copy()

siphash24.pyx.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cdef bytes uint64le(uint64_t v):
3232
return <bytes>r[:8]
3333

3434

35-
cdef bytes hexlify(uint64_t v):
35+
cdef str hexlify(uint64_t v):
3636
cdef char string[17]
3737
PyOS_snprintf(
3838
string, sizeof(string),
@@ -45,7 +45,7 @@ cdef bytes hexlify(uint64_t v):
4545
<uint8_t>(v >> 40),
4646
<uint8_t>(v >> 48),
4747
<uint8_t>(v >> 56))
48-
return <bytes>string[:16]
48+
return string[:16].decode('ascii')
4949

5050

5151
{{for variant in "13", "24"}}

test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_siphash24_data_and_key(self):
3232
def test_siphash24_hexdigest(self):
3333
h = siphash24.siphash24()
3434
self.assertIsInstance(h.digest(), bytes)
35-
self.assertEqual(h.hexdigest(), binascii.hexlify(h.digest()))
35+
self.assertEqual(h.hexdigest(), binascii.hexlify(h.digest()).decode('ascii'))
3636

3737
def test_siphash24_name(self):
3838
h = siphash24.siphash24()

0 commit comments

Comments
 (0)