Skip to content

Commit bea439d

Browse files
authored
Merge pull request #283 from tlsfuzzer/fix-py3.3-compat
workaround py3.3 bug with empty strings and memoryview
2 parents 4a8b1e3 + c9000ec commit bea439d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/ecdsa/_compat.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,24 @@ def hmac_compat(data):
100100
return bytes(data)
101101
return data
102102

103+
def normalise_bytes(buffer_object):
104+
"""Cast the input into array of bytes."""
105+
if not buffer_object:
106+
return b""
107+
return memoryview(buffer_object).cast("B")
108+
103109
else:
104110

105111
def hmac_compat(data):
106112
return data
107113

114+
def normalise_bytes(buffer_object):
115+
"""Cast the input into array of bytes."""
116+
return memoryview(buffer_object).cast("B")
117+
108118
def compat26_str(val):
109119
return val
110120

111-
def normalise_bytes(buffer_object):
112-
"""Cast the input into array of bytes."""
113-
return memoryview(buffer_object).cast("B")
114-
115121
def remove_whitespace(text):
116122
"""Removes all whitespace from passed in string"""
117123
return re.sub(r"\s+", "", text, flags=re.UNICODE)

src/ecdsa/test_keys.py

+9
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,15 @@ def test_equality_on_signing_keys(self):
550550
self.assertEqual(self.sk1, sk)
551551
self.assertEqual(self.sk1_pkcs8, sk)
552552

553+
def test_verify_with_empty_message(self):
554+
sig = self.sk1.sign(b"")
555+
556+
self.assertTrue(sig)
557+
558+
vk = self.sk1.verifying_key
559+
560+
self.assertTrue(vk.verify(sig, b""))
561+
553562
def test_verify_with_precompute(self):
554563
sig = self.sk1.sign(b"message")
555564

0 commit comments

Comments
 (0)