-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Annotate jwt.algorithms #2532
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
Annotate jwt.algorithms #2532
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
from typing import Any | ||
import sys | ||
from hashlib import _Hash | ||
from typing import Any, Set, Dict, Optional, ClassVar, Union, Generic, TypeVar | ||
|
||
class Algorithm(Any): ... # type: ignore | ||
requires_cryptography = Set[str] | ||
|
||
def get_default_algorithms() -> Dict[str, Algorithm]: ... | ||
|
||
_K = TypeVar("_K") | ||
|
||
class Algorithm(Generic[_K]): | ||
def prepare_key(self, key: _K) -> _K: ... | ||
def sign(self, msg: bytes, key: _K) -> bytes: ... | ||
def verify(self, msg: bytes, key: _K, sig: bytes) -> bool: ... | ||
@staticmethod | ||
def to_jwk(key_obj: _K) -> str: ... | ||
@staticmethod | ||
def from_jwk(jwk: str) -> _K: ... | ||
|
||
class NoneAlgorithm(Algorithm[None]): | ||
def prepare_key(self, key: Optional[str]) -> None: ... | ||
|
||
class _HashAlg: | ||
def __call__(self, arg: Union[bytes, bytearray, memoryview] = ...) -> _Hash: ... | ||
|
||
if sys.version_info >= (3, 6): | ||
_LoadsString = Union[str, bytes, bytearray] | ||
else: | ||
_LoadsString = str | ||
|
||
class HMACAlgorithm(Algorithm[bytes]): | ||
SHA256: ClassVar[_HashAlg] | ||
SHA384: ClassVar[_HashAlg] | ||
SHA512: ClassVar[_HashAlg] | ||
has_alg: _HashAlg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
def __init__(self, _HashAlg) -> None: ... | ||
def prepare_key(self, key: Union[str, bytes]) -> bytes: ... | ||
@staticmethod | ||
def to_jwk(key_obj: Union[str, bytes]) -> Any: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to actually return |
||
@staticmethod | ||
def from_jwk(jwk: _LoadsString) -> bytes: ... | ||
|
||
# If cryptography is installed, also has classes RSAAlgorithm and ECAlgorithm. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also have stubs for these classes then. False negatives are better than false positives. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I left them out for now, since we don't have stubs for cryptography, yet, but we could of course use |
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 don't think this works correctly:
This is python/mypy#1337.
There doesn't appear to be a good workaround, so we may have to use
Any
for now.