Skip to content

Commit d9baf10

Browse files
committed
Raise exception for incorrectly encoded signing key
1 parent 5c386d1 commit d9baf10

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

common/exceptions.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,24 @@ class InvalidEncodedSignatureError(DSKEException):
335335
def __init__(self, encoded_signature: str):
336336
super().__init__(
337337
status_code=status.HTTP_400_BAD_REQUEST,
338-
message="Invalid encoded fragment.",
338+
message="Invalid encoded signature.",
339339
details={"encoded_signature": encoded_signature},
340340
)
341341

342342

343+
class InvalidEncodedSigningKeyError(DSKEException):
344+
"""
345+
Exception raised when trying to parse an encoded signing key string that is invalid.
346+
"""
347+
348+
def __init__(self, encoded_signing_key: str):
349+
super().__init__(
350+
status_code=status.HTTP_400_BAD_REQUEST,
351+
message="Invalid encoded signing key.",
352+
details={"encoded_signing_key": encoded_signing_key},
353+
)
354+
355+
343356
class EncryptorNotRegisteredForClientError(DSKEException):
344357
"""
345358
Exception raised when an encryptor is not registered for a client.

common/signing_key.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import hashlib
66
import hmac
77
from .allocation import Allocation
8+
from .exceptions import InvalidEncodedSigningKeyError
89
from .pool import Pool
910
from .signature import Signature
1011
from .utils import bytes_to_str, str_to_bytes
@@ -98,7 +99,7 @@ def from_enc_str(cls, enc_str: str) -> "SigningKey":
9899
"""
99100
split_str = enc_str.split(_ENCODING_SEPARATOR)
100101
if len(split_str) != 2:
101-
assert False # TODO: Raise an exception instead
102+
raise InvalidEncodedSigningKeyError(enc_str)
102103
allocation_enc_str = split_str[0]
103104
key_data_str = split_str[1]
104105
key_data = str_to_bytes(key_data_str)

0 commit comments

Comments
 (0)