Skip to content

Commit

Permalink
fix: clean useless except of binascii.Error
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Jul 28, 2023
1 parent bfd7d1f commit c98cfd7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/joserfc/rfc7515/compact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import binascii
import typing as t
from .model import JWSAlgModel, CompactSignature
from ..errors import DecodeError, MissingAlgorithmError
Expand Down Expand Up @@ -33,7 +32,7 @@ def extract_compact(value: bytes) -> CompactSignature:

try:
payload = urlsafe_b64decode(payload_segment)
except (TypeError, ValueError, binascii.Error):
except (TypeError, ValueError):
raise DecodeError("Invalid payload")

obj = CompactSignature(protected, payload)
Expand Down Expand Up @@ -63,6 +62,6 @@ def decode_header(header_segment: bytes) -> t.Dict[str, t.Any]:
protected = json_b64decode(header_segment)
if "alg" not in protected:
raise MissingAlgorithmError()
except (TypeError, ValueError, binascii.Error):
except (TypeError, ValueError):
raise DecodeError("Invalid header")
return protected
5 changes: 2 additions & 3 deletions src/joserfc/rfc7515/json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import typing as t
import binascii
import copy
from .model import (
HeaderMember,
Expand Down Expand Up @@ -82,7 +81,7 @@ def extract_general_json(value: GeneralJSONSerialization) -> GeneralJSONSignatur
payload_segment: bytes = value["payload"].encode("utf-8")
try:
payload = urlsafe_b64decode(payload_segment)
except (TypeError, ValueError, binascii.Error):
except (TypeError, ValueError):
raise DecodeError("Invalid payload")

signatures: t.List[JSONSignatureDict] = value["signatures"]
Expand All @@ -97,7 +96,7 @@ def extract_flattened_json(value: FlattenedJSONSerialization) -> FlattenedJSONSi
payload_segment: bytes = value["payload"].encode("utf-8")
try:
payload = urlsafe_b64decode(payload_segment)
except (TypeError, ValueError, binascii.Error):
except (TypeError, ValueError):
raise DecodeError("Invalid payload")

_sig: JSONSignatureDict = {"signature": value["signature"]}
Expand Down
3 changes: 1 addition & 2 deletions src/joserfc/rfc7516/compact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import binascii
from .models import CompactEncryption, Recipient
from ..errors import (
MissingAlgorithmError,
Expand Down Expand Up @@ -37,7 +36,7 @@ def extract_compact(value: bytes) -> CompactEncryption:
raise MissingAlgorithmError()
if "enc" not in protected:
raise MissingEncryptionError()
except (TypeError, ValueError, binascii.Error):
except (TypeError, ValueError):
raise DecodeError("Invalid header")

obj = CompactEncryption(protected)
Expand Down
2 changes: 1 addition & 1 deletion src/joserfc/rfc7518/rsa_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ def has_all_prime_factors(obj) -> bool:
return True

if any(props_found):
raise ValueError("RSA key must include all parameters " "if any are present besides d")
raise ValueError("RSA key must include all parameters if any are present besides d")

return False
5 changes: 2 additions & 3 deletions src/joserfc/rfc8037/okp_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ class OKPKey(CurveKey[PrivateOKPKey, PublicOKPKey]):
def exchange_derive_key(self, key: "OKPKey") -> bytes:
# used in ECDHESAlgorithm
pubkey: t.Union[X25519PublicKey, X448PublicKey] = key.get_op_key("deriveKey") # type: ignore
if isinstance(self.private_key, X25519PrivateKey) and isinstance(pubkey, X25519PublicKey):
return self.private_key.exchange(pubkey)
elif isinstance(self.private_key, X448PrivateKey) and isinstance(pubkey, X448PublicKey):
if (isinstance(self.private_key, X25519PrivateKey) and isinstance(pubkey, X25519PublicKey)) or \
(isinstance(self.private_key, X448PrivateKey) and isinstance(pubkey, X448PublicKey)):
return self.private_key.exchange(pubkey)
raise ValueError("Invalid key for exchanging shared key")

Expand Down

0 comments on commit c98cfd7

Please sign in to comment.