Skip to content
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

Add more types #843

Merged
merged 3 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions jwt/algorithms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import hashlib
import hmac
import json
from typing import Any, Dict, Union
from typing import Any, ClassVar, Dict, Type, Union

from .exceptions import InvalidKeyError
from .types import JWKDict
from .types import HashlibHash, JWKDict
from .utils import (
base64url_decode,
base64url_encode,
Expand Down Expand Up @@ -212,11 +212,11 @@ class HMACAlgorithm(Algorithm):
and the specified hash function.
"""

SHA256 = hashlib.sha256
SHA384 = hashlib.sha384
SHA512 = hashlib.sha512
SHA256: ClassVar[HashlibHash] = hashlib.sha256
SHA384: ClassVar[HashlibHash] = hashlib.sha384
SHA512: ClassVar[HashlibHash] = hashlib.sha512

def __init__(self, hash_alg) -> None:
def __init__(self, hash_alg: HashlibHash) -> None:
self.hash_alg = hash_alg

def prepare_key(self, key):
Expand Down Expand Up @@ -271,11 +271,11 @@ class RSAAlgorithm(Algorithm):
RSASSA-PKCS-v1_5 and the specified hash function.
"""

SHA256 = hashes.SHA256
SHA384 = hashes.SHA384
SHA512 = hashes.SHA512
SHA256: ClassVar[Type[hashes.HashAlgorithm]] = hashes.SHA256
SHA384: ClassVar[Type[hashes.HashAlgorithm]] = hashes.SHA384
SHA512: ClassVar[Type[hashes.HashAlgorithm]] = hashes.SHA512

def __init__(self, hash_alg) -> None:
def __init__(self, hash_alg: Type[hashes.HashAlgorithm]) -> None:
self.hash_alg = hash_alg

def prepare_key(self, key):
Expand Down Expand Up @@ -419,11 +419,11 @@ class ECAlgorithm(Algorithm):
ECDSA and the specified hash function
"""

SHA256 = hashes.SHA256
SHA384 = hashes.SHA384
SHA512 = hashes.SHA512
SHA256: ClassVar[Type[hashes.HashAlgorithm]] = hashes.SHA256
SHA384: ClassVar[Type[hashes.HashAlgorithm]] = hashes.SHA384
SHA512: ClassVar[Type[hashes.HashAlgorithm]] = hashes.SHA512

def __init__(self, hash_alg) -> None:
def __init__(self, hash_alg: Type[hashes.HashAlgorithm]) -> None:
self.hash_alg = hash_alg

def prepare_key(self, key):
Expand Down
4 changes: 2 additions & 2 deletions jwt/jwk_set_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


class JWKSetCache:
def __init__(self, lifespan: int):
def __init__(self, lifespan: int) -> None:
self.jwk_set_with_timestamp: Optional[PyJWTSetWithTimestamp] = None
self.lifespan = lifespan

def put(self, jwk_set: PyJWKSet):
def put(self, jwk_set: PyJWKSet) -> None:
if jwk_set is not None:
self.jwk_set_with_timestamp = PyJWTSetWithTimestamp(jwk_set)
else:
Expand Down
4 changes: 3 additions & 1 deletion jwt/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Dict
from typing import Any, Callable, Dict

JWKDict = Dict[str, Any]

HashlibHash = Callable[..., Any]
Viicos marked this conversation as resolved.
Show resolved Hide resolved