@@ -23,12 +23,7 @@ def __init__(self, description: str | None = None):
2323 super (JoseError , self ).__init__ (message )
2424
2525
26- class DecodeError (JoseError ):
27- """This error is designed for JWS/JWE. It is raised when deserialization
28- and decryption fails.
29- """
30-
31- error = "decode_error"
26+ # --- Key related errors --- #
3227
3328
3429class MissingKeyError (JoseError ):
@@ -47,10 +42,6 @@ class UnsupportedKeyOperationError(JoseError):
4742 error = "unsupported_key_operation"
4843
4944
50- class InvalidKeyLengthError (JoseError ):
51- error = "invalid_key_length"
52-
53-
5445class MissingKeyTypeError (JoseError ):
5546 error = "missing_key_type"
5647
@@ -59,25 +50,35 @@ class InvalidKeyTypeError(JoseError):
5950 error = "invalid_key_type"
6051
6152
62- class InvalidKeyCurveError (JoseError ):
63- error = "invalid_key_curve"
64-
65-
6653class InvalidKeyIdError (JoseError ):
54+ """This error is designed for Key Set. It is raised when a key
55+ can not be found with the given key ID."""
56+
6757 error = "invalid_key_id"
6858
6959
7060class InvalidExchangeKeyError (JoseError ):
61+ """This error is designed for EC and OKP keys. It is raised when
62+ exchanging derive key failed."""
63+
7164 error = "invalid_exchange_key"
7265 description = "Invalid key for exchanging shared key"
7366
7467
75- class InvalidEncryptedKeyError (JoseError ):
76- error = "invalid_encrypted_key"
77- description = "JWE Encrypted Key value SHOULD be an empty octet sequence"
68+ # --- JWS & JWE related errors --- #
69+
70+
71+ class DecodeError (JoseError ):
72+ """This error is designed for both JWS and JWE. It is raised when deserialization
73+ and decryption fails.
74+ """
75+
76+ error = "decode_error"
7877
7978
8079class MissingAlgorithmError (JoseError ):
80+ """Raised when an algorithm ("alg") is missing."""
81+
8182 error = "missing_algorithm"
8283 description = "Missing 'alg' value in header"
8384
@@ -87,14 +88,22 @@ class ConflictAlgorithmError(JoseError):
8788
8889
8990class UnsupportedAlgorithmError (JoseError ):
91+ """This error is designed for both JWS and JWE. It is raised when the
92+ given algorithm is not supported in the registry.
93+ """
94+
9095 error = "unsupported_algorithm"
9196
9297
9398class InvalidHeaderValueError (JoseError ):
99+ """Raised when the given header's value is invalid."""
100+
94101 error = "invalid_header_value"
95102
96103
97104class UnsupportedHeaderError (JoseError ):
105+ """Raised when an unsupported header is encountered."""
106+
98107 error = "unsupported_header"
99108
100109
@@ -126,8 +135,24 @@ class MissingEncryptionError(JoseError):
126135 description = "Missing 'enc' value in header"
127136
128137
138+ class InvalidKeyCurveError (JoseError ):
139+ """This error is designed for JWS. It is raised when key's
140+ curve name does not match with the given algorithm.
141+ """
142+
143+ error = "invalid_key_curve"
144+
145+
146+ class InvalidKeyLengthError (JoseError ):
147+ """This error is designed for JWE. It is raised when key's
148+ length does not align with the given algorithm.
149+ """
150+
151+ error = "invalid_key_length"
152+
153+
129154class BadSignatureError (JoseError ):
130- """This error is designed for JWS/JWT . It is raised when signature
155+ """This error is designed for JWS. It is raised when signature
131156 does not match.
132157 """
133158
@@ -149,6 +174,11 @@ class InvalidEncryptionAlgorithmError(JoseError):
149174 error = "invalid_encryption_algorithm"
150175
151176
177+ class InvalidEncryptedKeyError (JoseError ):
178+ error = "invalid_encrypted_key"
179+ description = "JWE Encrypted Key value SHOULD be an empty octet sequence"
180+
181+
152182class InvalidCEKLengthError (JoseError ):
153183 error = "invalid_cek_length"
154184 description = "Invalid 'cek' length"
@@ -158,6 +188,9 @@ def __init__(self, cek_size: int): # pragma: no cover
158188 super (InvalidCEKLengthError , self ).__init__ (description = description )
159189
160190
191+ # --- JWT related errors --- #
192+
193+
161194class InvalidClaimError (JoseError ):
162195 """This error is designed for JWT. It raised when the claim contains
163196 invalid values or types."""
0 commit comments