diff --git a/jwt/algorithms.py b/jwt/algorithms.py index 54b574fa4..5cac550c9 100644 --- a/jwt/algorithms.py +++ b/jwt/algorithms.py @@ -82,17 +82,19 @@ def verify(self, msg, key, sig): """ raise NotImplementedError - def to_jwk(self, key_obj): + @staticmethod + def to_jwk(key_obj): """ Serializes a given RSA key into a JWK """ raise NotImplementedError - def from_jwk(self, jwk): + @staticmethod + def from_jwk(jwk): """ Deserializes a given RSA key from JWK back into a PublicKey or PrivateKey object """ - return NotImplementedError + raise NotImplementedError class NoneAlgorithm(Algorithm): @@ -109,14 +111,6 @@ def prepare_key(self, key): return key - @staticmethod - def to_jwk(key_obj): - return {} - - @staticmethod - def from_jwk(jwk): - return None - def sign(self, msg, key): return b'' diff --git a/tests/test_algorithms.py b/tests/test_algorithms.py index 7fef9635d..818c56b67 100644 --- a/tests/test_algorithms.py +++ b/tests/test_algorithms.py @@ -36,6 +36,18 @@ def test_algorithm_should_throw_exception_if_verify_not_impl(self): with pytest.raises(NotImplementedError): algo.verify('message', 'key', 'signature') + def test_algorithm_should_throw_exception_if_to_jwk_not_impl(self): + algo = Algorithm() + + with pytest.raises(NotImplementedError): + algo.from_jwk('value') + + def test_algorithm_should_throw_exception_if_from_jwk_not_impl(self): + algo = Algorithm() + + with pytest.raises(NotImplementedError): + algo.to_jwk('value') + def test_none_algorithm_should_throw_exception_if_key_is_not_none(self): algo = NoneAlgorithm()