Skip to content

Commit

Permalink
Merge pull request #101 from mark-adams/pyjwt-obj
Browse files Browse the repository at this point in the history
Refactor api.py functions into an object (PyJWT)
  • Loading branch information
jpadilla committed Mar 17, 2015
2 parents d471631 + a72cf6d commit 1e6b6c5
Show file tree
Hide file tree
Showing 5 changed files with 1,098 additions and 1,036 deletions.
2 changes: 1 addition & 1 deletion jwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
__copyright__ = 'Copyright 2015 José Padilla'


from .api import encode, decode, register_algorithm
from .api import encode, decode, register_algorithm, PyJWT
from .exceptions import (
InvalidTokenError, DecodeError, ExpiredSignatureError,
InvalidAudienceError, InvalidIssuerError,
Expand Down
23 changes: 11 additions & 12 deletions jwt/algorithms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import hashlib
import hmac

from .api import register_algorithm
from .compat import constant_time_compare, string_types, text_type

try:
Expand All @@ -18,23 +17,23 @@
has_crypto = False


def _register_default_algorithms():
def _register_default_algorithms(pyjwt_obj):
"""
Registers the algorithms that are implemented by the library.
"""
register_algorithm('none', NoneAlgorithm())
register_algorithm('HS256', HMACAlgorithm(HMACAlgorithm.SHA256))
register_algorithm('HS384', HMACAlgorithm(HMACAlgorithm.SHA384))
register_algorithm('HS512', HMACAlgorithm(HMACAlgorithm.SHA512))
pyjwt_obj.register_algorithm('none', NoneAlgorithm())
pyjwt_obj.register_algorithm('HS256', HMACAlgorithm(HMACAlgorithm.SHA256))
pyjwt_obj.register_algorithm('HS384', HMACAlgorithm(HMACAlgorithm.SHA384))
pyjwt_obj.register_algorithm('HS512', HMACAlgorithm(HMACAlgorithm.SHA512))

if has_crypto:
register_algorithm('RS256', RSAAlgorithm(RSAAlgorithm.SHA256))
register_algorithm('RS384', RSAAlgorithm(RSAAlgorithm.SHA384))
register_algorithm('RS512', RSAAlgorithm(RSAAlgorithm.SHA512))
pyjwt_obj.register_algorithm('RS256', RSAAlgorithm(RSAAlgorithm.SHA256))
pyjwt_obj.register_algorithm('RS384', RSAAlgorithm(RSAAlgorithm.SHA384))
pyjwt_obj.register_algorithm('RS512', RSAAlgorithm(RSAAlgorithm.SHA512))

register_algorithm('ES256', ECAlgorithm(ECAlgorithm.SHA256))
register_algorithm('ES384', ECAlgorithm(ECAlgorithm.SHA384))
register_algorithm('ES512', ECAlgorithm(ECAlgorithm.SHA512))
pyjwt_obj.register_algorithm('ES256', ECAlgorithm(ECAlgorithm.SHA256))
pyjwt_obj.register_algorithm('ES384', ECAlgorithm(ECAlgorithm.SHA384))
pyjwt_obj.register_algorithm('ES512', ECAlgorithm(ECAlgorithm.SHA512))


class Algorithm(object):
Expand Down
Loading

0 comments on commit 1e6b6c5

Please sign in to comment.