From f254895b02f0cb106f9ccee6d8dc6af1a27f0bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Sun, 15 Nov 2020 16:18:18 +0100 Subject: 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. --- rsa/pkcs1.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'rsa/pkcs1.py') diff --git a/rsa/pkcs1.py b/rsa/pkcs1.py index 8a85b1c..d0149a1 100644 --- a/rsa/pkcs1.py +++ b/rsa/pkcs1.py @@ -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 -- cgit v1.2.1