Skip to content

Commit

Permalink
Use bytes.find() instead of bytes.index()
Browse files Browse the repository at this point in the history
Use `bytes.find()` instead of `bytes.index()`, as the former doesn't raise
an exception when the to-be-found byte doesn't exist.
  • Loading branch information
sybrenstuvel committed Nov 15, 2020
1 parent 240b0d8 commit f254895
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions rsa/pkcs1.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,8 @@ def decrypt(crypto: bytes, priv_key: key.PrivateKey) -> bytes:
cleartext_marker_bad = not compare_digest(cleartext[:2], b'\x00\x02')

# Find the 00 separator between the padding and the message
try:
sep_idx = cleartext.index(b'\x00', 2)
except ValueError:
sep_idx = -1
sep_idx = cleartext.find(b'\x00', 2)

# sep_idx indicates the position of the `\x00` separator that separates the
# padding from the actual message. The padding should be at least 8 bytes
# long (see https://tools.ietf.org/html/rfc8017#section-7.2.2 step 3), which
Expand Down

0 comments on commit f254895

Please sign in to comment.