Skip to content

Commit

Permalink
Cleanup on JWK
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-adams committed May 7, 2016
1 parent 80da356 commit 3466f90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 5 additions & 11 deletions jwt/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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''

Expand Down
12 changes: 12 additions & 0 deletions tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 3466f90

Please sign in to comment.