File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -464,13 +464,8 @@ def unpem(pem):
464464 if isinstance (pem , text_type ): # pragma: no branch
465465 pem = pem .encode ()
466466
467- d = b"" .join (
468- [
469- l .strip ()
470- for l in pem .split (b"\n " )
471- if l and not l .startswith (b"-----" )
472- ]
473- )
467+ lines = (l .strip () for l in pem .split (b"\n " ))
468+ d = b"" .join (l for l in lines if l and not l .startswith (b"-----" ))
474469 return base64 .b64decode (d )
475470
476471
Original file line number Diff line number Diff line change 2626 remove_octet_string ,
2727 remove_sequence ,
2828 encode_implicit ,
29+ unpem ,
30+ topem ,
2931)
3032
3133
@@ -629,3 +631,16 @@ def test_remove_implicit_rejects_truncated_length():
629631 UnexpectedDER , match = "Length longer than the provided buffer"
630632 ):
631633 remove_implicit (bad )
634+
635+
636+ def test_unpem_with_str ():
637+ data = b"\xff \x00 \x01 "
638+ encoded = topem (data , "KEY" )
639+ if sys .version_info < (3 , 0 ):
640+ # on python2 the string can be unicode
641+ encoded = unicode (encoded )
642+ else :
643+ # on python3 topem() returns bytes
644+ encoded = str (encoded , "ASCII" )
645+ out = unpem (encoded )
646+ assert data == out
You can’t perform that action at this time.
0 commit comments