diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2020-11-15 16:18:18 +0100 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2020-11-15 16:18:18 +0100 |
commit | f254895b02f0cb106f9ccee6d8dc6af1a27f0bd1 (patch) | |
tree | d1e6997076de361d258c322ff73b15c50d9e5984 | |
parent | 240b0d8910299f970921391ea9737cb64ec09208 (diff) | |
download | rsa-f254895b02f0cb106f9ccee6d8dc6af1a27f0bd1.tar.gz |
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.
-rw-r--r-- | rsa/pkcs1.py | 6 |
1 files changed, 2 insertions, 4 deletions
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 |