Skip to content

Commit f254895

Browse files
committed
Use bytes.find() instead of bytes.index()
Use `bytes.find()` instead of `bytes.index()`, as the former doesn't raise an exception when the to-be-found byte doesn't exist.
1 parent 240b0d8 commit f254895

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

rsa/pkcs1.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,8 @@ def decrypt(crypto: bytes, priv_key: key.PrivateKey) -> bytes:
258258
cleartext_marker_bad = not compare_digest(cleartext[:2], b'\x00\x02')
259259

260260
# Find the 00 separator between the padding and the message
261-
try:
262-
sep_idx = cleartext.index(b'\x00', 2)
263-
except ValueError:
264-
sep_idx = -1
261+
sep_idx = cleartext.find(b'\x00', 2)
262+
265263
# sep_idx indicates the position of the `\x00` separator that separates the
266264
# padding from the actual message. The padding should be at least 8 bytes
267265
# long (see https://tools.ietf.org/html/rfc8017#section-7.2.2 step 3), which

0 commit comments

Comments
 (0)