Skip to content
Open
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
10 changes: 6 additions & 4 deletions lib/Crypto/IO/PEM.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ def decode(pem_data, passphrase=None):
raise ValueError("Not a valid PEM pre boundary")
marker = m.group(1)

# Verify Post-Encapsulation Boundary
r = re.compile(r"-----END (.*)-----\s*$")
m = r.search(pem_data)
if not m or m.group(1) != marker:
# Verify Post-Encapsulation Boundary.
# The marker is already known from the pre-boundary, so the boundary can be
# matched directly. Searching for it with r"-----END (.*)-----\s*$" was
# quadratic in len(pem_data): every "-----END " is a start position for the
# search, and the greedy (.*) backtracks the whole remainder at each one.
if not pem_data.rstrip().endswith("-----END %s-----" % marker):
raise ValueError("Not a valid PEM post boundary")

# Removes spaces and slit on lines
Expand Down
Loading