-
-
Notifications
You must be signed in to change notification settings - Fork 688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Back from the dead: PyCrypto and ECDSA #103
Conversation
- Algorithms now have SHA256, SHA384, and SHA512 static properties that refer to the callable that instantiates their hash class - All algorithms now expect a class (callable) as their hash_alg now. This behavior was inconsistent before.
@mark-adams dude this is pure gold right here! |
@@ -86,6 +86,8 @@ class HMACAlgorithm(Algorithm): | |||
def __init__(self, hash_alg): | |||
self.hash_alg = hash_alg | |||
|
|||
SHA256, SHA384, SHA512 = hashlib.sha256, hashlib.sha384, hashlib.sha512 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer to change the style of these everywhere to separate lines and before the __init__
method. I think it's easier to parse.
class HMACAlgorithm(Algorithm):
"""
Performs signing and verification operations using HMAC
and the specified hash function.
"""
SHA256 = hashlib.sha256
SHA384 = hashlib.sha384
SHA512 = hashlib.sha512
def __init__(self, hash_alg):
self.hash_alg = hash_alg
@jpadilla Thanks!! I think you're right about the hash function variables. I debated which way to lay them out for a while and was torn between my way and the way you suggested. You're probably right, it is more readable your way. I went ahead and made the change. |
Back from the dead: PyCrypto and ECDSA
This PR takes care of a chunk of the work towards resolving #99. Specifically, it accomplishes two things:
jwt.contrib.algorithms
modulejwt.algorithms
as well as thejwt.contrib.algorithms
now have static class variables for SHA256, SHA384, and SHA512 to make our default registration code a little simpler (it no longer has to know the specifics about the hash objects). This also could eventually allow us to write some shared test code between the preferred andjwt.contrib.algorithms
algorithms.This PR would allow a consumer to call register_algorithm and pass in the
RSAAlgorithm
or theECAlgorithm
fromjwt.contrib.algorithms
if they would like to use the legacy libraries. I think we could make our default algorithms code much more complex by trying to autodetect all three libraries (cryptography, pycrypto, and ecdsa) but I think it is much simpler for us to only detect for cryptography and simply make the other algorithms available for those on AppEngine or other environments where they need specific support.