Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/ecdsa/der.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,8 @@ def unpem(pem):
if isinstance(pem, text_type): # pragma: no branch
pem = pem.encode()

d = b"".join(
[
l.strip()
for l in pem.split(b"\n")
if l and not l.startswith(b"-----")
]
)
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"-----"))
return base64.b64decode(d)


Expand Down
15 changes: 15 additions & 0 deletions src/ecdsa/test_der.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
remove_octet_string,
remove_sequence,
encode_implicit,
unpem,
topem,
)


Expand Down Expand Up @@ -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
Loading