From f8e0f3a0035b44fa2541e2c447ed1599f220c4b5 Mon Sep 17 00:00:00 2001 From: Alexander Shadchin Date: Thu, 9 Apr 2026 12:22:29 +0300 Subject: [PATCH 1/3] Fix tests with new Python --- src/ecdsa/der.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ecdsa/der.py b/src/ecdsa/der.py index 5d35d698..587d7852 100644 --- a/src/ecdsa/der.py +++ b/src/ecdsa/der.py @@ -464,12 +464,11 @@ def unpem(pem): if isinstance(pem, text_type): # pragma: no branch pem = pem.encode() + lines = (l.strip() for l in pem.split(b"\n")) d = b"".join( - [ - l.strip() - for l in pem.split(b"\n") - if l and not l.startswith(b"-----") - ] + l + for l in lines + if l and not l.startswith(b"-----") ) return base64.b64decode(d) From adaf864144b25e621f6109f369874345c138a644 Mon Sep 17 00:00:00 2001 From: Alicja Kario Date: Fri, 5 Jun 2026 12:45:31 +0200 Subject: [PATCH 2/3] fix formatting --- src/ecdsa/der.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/ecdsa/der.py b/src/ecdsa/der.py index 587d7852..fc31a50e 100644 --- a/src/ecdsa/der.py +++ b/src/ecdsa/der.py @@ -465,11 +465,7 @@ def unpem(pem): pem = pem.encode() lines = (l.strip() for l in pem.split(b"\n")) - d = b"".join( - l - for l in lines - if l and not l.startswith(b"-----") - ) + d = b"".join(l for l in lines if l and not l.startswith(b"-----")) return base64.b64decode(d) From a80ceaf76b67bdaaa8b1958b94a58536fff3238a Mon Sep 17 00:00:00 2001 From: Alicja Kario Date: Fri, 5 Jun 2026 13:00:37 +0200 Subject: [PATCH 3/3] add test coverage for the str() case in unpem --- src/ecdsa/test_der.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ecdsa/test_der.py b/src/ecdsa/test_der.py index 26909bc6..bbddf5eb 100644 --- a/src/ecdsa/test_der.py +++ b/src/ecdsa/test_der.py @@ -26,6 +26,8 @@ remove_octet_string, remove_sequence, encode_implicit, + unpem, + topem, ) @@ -629,3 +631,16 @@ def test_remove_implicit_rejects_truncated_length(): UnexpectedDER, match="Length longer than the provided buffer" ): remove_implicit(bad) + + +def test_unpem_with_str(): + data = b"\xff\x00\x01" + encoded = topem(data, "KEY") + if sys.version_info < (3, 0): + # on python2 the string can be unicode + encoded = unicode(encoded) + else: + # on python3 topem() returns bytes + encoded = str(encoded, "ASCII") + out = unpem(encoded) + assert data == out