File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -321,12 +321,25 @@ class InvalidEncodedFragment(DSKEException):
321321
322322 def __init__ (self , encoded_fragment : str ):
323323 super ().__init__ (
324- status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
324+ status_code = status .HTTP_400_BAD_REQUEST
325325 message = "Invalid encoded fragment." ,
326326 details = {"encoded_fragment" : encoded_fragment },
327327 )
328328
329329
330+ class InvalidEncodedSignature (DSKEException ):
331+ """
332+ Exception raised when trying to parse an encoded signature string that is invalid.
333+ """
334+
335+ def __init__ (self , encoded_signature : str ):
336+ super ().__init__ (
337+ status_code = status .HTTP_400_BAD_REQUEST
338+ message = "Invalid encoded fragment." ,
339+ details = {"encoded_signature" : encoded_signature },
340+ )
341+
342+
330343class EncryptorNotRegisteredForClientError (DSKEException ):
331344 """
332345 Exception raised when an encryptor is not registered for a client.
Original file line number Diff line number Diff line change 33"""
44
55from typing import Optional
6+ from .exceptions import InvalidEncodedSignatureError
67from .utils import bytes_to_str , str_to_bytes
78
89HEADER_NAME = "DSKE-Signature"
@@ -51,7 +52,7 @@ def from_enc_str(cls, enc_str: str) -> "Signature":
5152 """
5253 split_str = enc_str .split (_ENCODING_SEPARATOR )
5354 if len (split_str ) != 2 :
54- assert False # TODO: Raise an exception instead
55+ raise InvalidEncodedSignatureError ( enc_str )
5556 allocation_enc_str = split_str [0 ]
5657 signature_data_str = split_str [1 ]
5758 signature_data = str_to_bytes (signature_data_str )
You can’t perform that action at this time.
0 commit comments