Skip to content

Commit

Permalink
Merge pull request #283 from tlsfuzzer/fix-py3.3-compat
Browse files Browse the repository at this point in the history
workaround py3.3 bug with empty strings and memoryview
  • Loading branch information
tomato42 authored Jan 5, 2022
2 parents 4a8b1e3 + c9000ec commit bea439d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ecdsa/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,24 @@ def hmac_compat(data):
return bytes(data)
return data

def normalise_bytes(buffer_object):
"""Cast the input into array of bytes."""
if not buffer_object:
return b""
return memoryview(buffer_object).cast("B")

else:

def hmac_compat(data):
return data

def normalise_bytes(buffer_object):
"""Cast the input into array of bytes."""
return memoryview(buffer_object).cast("B")

def compat26_str(val):
return val

def normalise_bytes(buffer_object):
"""Cast the input into array of bytes."""
return memoryview(buffer_object).cast("B")

def remove_whitespace(text):
"""Removes all whitespace from passed in string"""
return re.sub(r"\s+", "", text, flags=re.UNICODE)
Expand Down
9 changes: 9 additions & 0 deletions src/ecdsa/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,15 @@ def test_equality_on_signing_keys(self):
self.assertEqual(self.sk1, sk)
self.assertEqual(self.sk1_pkcs8, sk)

def test_verify_with_empty_message(self):
sig = self.sk1.sign(b"")

self.assertTrue(sig)

vk = self.sk1.verifying_key

self.assertTrue(vk.verify(sig, b""))

def test_verify_with_precompute(self):
sig = self.sk1.sign(b"message")

Expand Down

0 comments on commit bea439d

Please sign in to comment.