summaryrefslogtreecommitdiff
path: root/jwt/algorithms.py
Commit message (Collapse)AuthorAgeFilesLines
* Add `as_dict` option to `Algorithm.to_jwk` (#881)Thitat Auareesuksakul2023-05-091-30/+109
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add `as_dict` option to `Algorithm.to_jwt` * Update unit tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixup! Add `as_dict` option to `Algorithm.to_jwt` * fixup! Add `as_dict` option to `Algorithm.to_jwt` * fixup! Update unit tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix type errors * Fix tox test errors * Fix typing for Python 3.7 * Add OKP jwk tests * Add `pragma: no cover` to method overloads * Add pragma: no cover to exclude lines --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add complete types to take all allowed keys into account (#873)Viicos2023-04-161-82/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Use new style typing * Fix type annotations to allow all keys * Use string type annotations where required * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove outdated comment * Ignore `if TYPE_CHECKING:` lines in coverage * Remove duplicate test * Fix mypy errors * Update algorithms.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fully switch to modern annotations * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update `pre-commit` mypy config * Use Python 3.11 for mypy * Update mypy Python version in `pyproject.toml` * Few tests mypy fixes * fix mypy errors on tests * Fix key imports * Remove unused import * Fix randomly failing test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
* Make `Algorithm` an abstract base class (#845)Viicos2023-03-061-10/+19
| | | | | | | | | | | * Make `Algorithm` an abstract base class This also removes some tests that are not relevant anymore Raise `NotImplementedError` for `NoneAlgorithm` * Use `hasattr` instead of `getattr` * Only allow `dict` in `encode`
* [pre-commit.ci] pre-commit autoupdate (#855)pre-commit-ci[bot]2023-02-071-1/+0
| | | | | | | | | | | | | | * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 22.12.0 → 23.1.0](https://github.com/psf/black/compare/22.12.0...23.1.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add more types (#843)Viicos2023-01-031-14/+14
| | | | | | | * Add return types in `JWKSetCache` * Add types for hash algorithms * Add missing type annotation in `ECAlgorithm`
* Make mypy configuration stricter and improve typing (#830)Aarni Koskela2022-12-101-42/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * PyJWS._verify_signature: raise early KeyError if header is missing alg * Make Mypy configuration stricter * Improve typing in jwt.utils * Improve typing in jwt.help * Improve typing in jwt.exceptions * Improve typing in jwt.api_jwk * Improve typing in jwt.api_jws * Improve typing & clean up imports in jwt.algorithms * Correct JWS.decode rettype to any (payload could be something else) * Update typing in api_jwt * Improve typing in jwks_client * Improve typing in docs/conf.py * Fix (benign) mistyping in test_advisory * Fix misc type complaints in tests
* Add `Algorithm.compute_hash_digest` and use it to implement at_hash ↵Stephen Rosen2022-11-021-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | validation example (#775) * Add compute_hash_digest to Algorithm objects `Algorithm.compute_hash_digest` is defined as a method which inspects the object to see that it has the requisite attributes, `hash_alg`. If `hash_alg` is not set, then the method raises a NotImplementedError. This applies to classes like NoneAlgorithm. If `hash_alg` is set, then it is checked for ``` has_crypto # is cryptography available? and isinstance(hash_alg, type) and issubclass(hash_alg, hashes.HashAlgorithm) ``` to see which API for computing a digest is appropriate -- `hashlib` vs `cryptography.hazmat.primitives.hashes`. These checks could be avoided at runtime if it were necessary to optimize further (e.g. attach compute_hash_digest methods to classes with a class decorator) but this is not clearly a worthwhile optimization. Such perf tuning is intentionally omitted for now. * Add doc example of OIDC login flow The goal of this doc example is to demonstrate usage of `get_algorithm_by_name` and `compute_hash_digest` for the purpose of `at_hash` validation. It is not meant to be a "guaranteed correct" and spec-compliant example. closes #314
* docs: fix simple typo, iinstance -> isinstance (#774)Tim Gates2022-07-031-1/+1
| | | | | There is a small typo in jwt/algorithms.py. Should read `isinstance` rather than `iinstance`.
* Add to_jwk static method to ECAlgorithm (#732)Leon Smith2022-05-231-0/+35
| | | | | | | | | | | | | | | | | * Add to_jwk static method to ECAlgorithm * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add in tests for ECAlgorithm.to_jwk * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add to_jwk pull request to changelog Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Merge pull request from GHSA-ffqj-6fqr-9h24José Padilla2022-05-121-21/+18
| | | Co-authored-by: José Padilla <jpadilla@users.noreply.github.com>
* Explicit check the key for ECAlgorithm (#713)Evgeniy Tatarkin2021-12-121-0/+6
| | | | | | | | | * Explicit check the key for ECAlgorithm * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Chore: inline Variables that immediately Returned (#690)Yasser Tahiri2021-10-031-30/+26
| | | | | * Fix Inline variables & Refactor Code Expression * Fix Linting Issue
* Add support for Ed448/EdDSA. (#675)Ajitomi, Daisuke2021-10-031-18/+32
| | | | | * Add support for Ed448/EdDSA. * Add test for verification using EdDSA private key.
* Add to_jwk to Ed25519Algorithm. (#642) (#643)JohannesWill2021-04-281-0/+43
| | | | | | | | | | | | | | | * Add to_jwk to Ed25519Algorithm. (#642) * add test for invalid key * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update CHANGELOG for #643 * remove alg from jwk Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Allow to verify with private key on ECAlgorithm, as well as on ↵Ajitomi, Daisuke2021-04-161-0/+2
| | | | | | | Ed25519Algorithm. (#645) * Add private key support for ECAlgorithm verify. * Update CHANGELOG.
* Add from_jwk to Ed25519Algorithm (Support kty: OKP). (#623)Ajitomi, Daisuke2021-03-181-0/+31
| | | | | * Support from_jwk on Ed25519Algorithm. * Update CHANGELOG.
* Support ES256K. (#629)Ajitomi, Daisuke2021-03-181-0/+9
| | | | | | | | | * Support ES256K. * Add tests for ES256K. * Add api_jws tests. * Update CHANGELOG.
* Fix `from_jwk()` for all algorithms (#598)José Padilla2021-01-111-3/+15
| | | | | * Fix `from_jwk()` for all algorithms * Update CHANGELOG.rst
* Use generator expressions (#569)Jon Dufresne2020-12-211-1/+1
| | | | Avoids building a list in memory unnecessarily. Generator expressions are evaluated lazily.
* Simplify black configuration to be closer to upstream defaults (#568)Jon Dufresne2020-12-211-12/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Simplify black configuration to be closer to upstream defaults Avoid extra configuration by simply going with Black defaults. This allows removing some configuration options, thus simplifying the overall configuration. It also makes the code style closer to community conventions. As more projects adopt black formatting, more code will look like the black defaults. Further, the default 88 tends to create more readable lines, IMO. The black rationale is located at: https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length * Update tests/test_api_jws.py Co-authored-by: José Padilla <jpadilla@webapplicate.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update tests/test_api_jws.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: José Padilla <jpadilla@webapplicate.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Prefer ModuleNotFoundError over ImportError (#565)Jon Dufresne2020-12-211-1/+1
| | | | | | | | | | | ModuleNotFoundError was introduced in Python 3. It is raised when the module does not exist. On the other hand, ImportError is raised during any import failure. For example, a syntax error or other runtime error. Using ModuleNotFoundError means that errors unrelated to a missing package will be propagated to the user. PyJWT doesn't know how to handle these. This also allows more functions to always be available for import
* Cleanup "noqa" comments (#553)Jon Dufresne2020-12-171-1/+1
| | | | - Remove "noqa" comments that are unnecessary - Remove unused imports from api_jwt.py
* Replace int_from_bytes() with builtin int.from_bytes() (#549)Jon Dufresne2020-12-171-4/+3
| | | | | | Follows upstream cryptography commit: https://github.com/pyca/cryptography/commit/5528a3182fdd6ed1c44c126d451a87bcf39e79de Since Python 3.2, this bytes to an int is a native feature.
* Tighten bytes/str boundaries and remove unnecessary coercing (#547)Jon Dufresne2020-12-171-16/+11
| | | | | | | | | | | | | | | | | | | Now that the project is Python 3 only, the boundaries between bytes and Unicode strings is more explicit. This allows removing several unnecessary force_bytes() and force_unicode() calls that handled differences between Python 2 and Python 3. All uses of force_unicode() have been removed. For values that are known to be bytes, use `.decode()` instead. For values are that known to be str, use `.encode()` instead. This strategy makes the type explicit and reduces a function call. Key handling continues to use force_bytes() to allow callers to pass either bytes or str. To help enforce bytes/str handling in the future, the `-b` option is passed to Python when testing. This option will emit a warning if bytes and str are improperly mixed together.
* Remove unnecessary force_bytes() calls priot to base64url_decode() (#543)Jon Dufresne2020-12-161-3/+3
| | | | | | | | | The first line of base64url_decode() is: if isinstance(input, str): input = input.encode("ascii") It therefore accepts either str or bytes. Don't bother coercing to bytes at the call site.
* Run pyupgrade to simplify code and use Python 3.6 syntax (#536)Jon Dufresne2020-12-161-1/+1
| | | | | | | | | | | | | | pyugrade is a command line tool to automatically update Python syntax to modern usage and patterns. For additional details, see: https://github.com/asottile/pyupgrade Changes made by the tool: - Use short Python3 super() syntax. - Use f-strings when they are simple and more readable. - Drop Python 2 u prefix from strings. - Drop "r" argument from open(). It is the default and so specifying it is unnecessary.
* Upgrade to isort 5 and adjust configurations (#533)Jon Dufresne2020-12-161-17/+16
| | | | | | | | | | | With isort 5, asottile/seed-isort-config is deprecated and unnecessary. The official isort main repo now has a pre-commit hook file. isort is now better at recognizing first party and third party packages. isort can now handle imports inside blocks, files have been updated. isort now supports "profiles" for simpler configuration.
* Removed redundant `default_backend()` (#523)Kaushal Rohit2020-10-121-26/+13
| | | - Cryptography now has default_backend by default
* Implementation of ECAlgorithm.from_jwk (#500)José Padilla2020-08-241-0/+62
| | | | | | | * ECAlgorithm.to_jwk * Fix failing linting Co-authored-by: Evert Lammerts <evert@lucipher.net>
* Drop support for legacy contrib algorithms (#514)José Padilla2020-08-241-9/+70
| | | | | * Drop support for legacy contrib algorithms * Update cryptography dep
* Introduce better experience for JWKs (#511)José Padilla2020-08-241-1/+6
| | | | | | | | | | | * Introduce better experience for JWKs * Remove explicit inheritance * Add tests for PyJWK * Fix failing test * Get rid of lambda
* Remove unnecessary compatibility shims for Python 2 (#498)Jon Dufresne2020-06-191-4/+3
| | | | | | | | | | | As the project is Python 3 only, can remove the compatibility shims in compat.py. Type checking has been simplified where it can: - str is iterable - bytes is iterable - use isinstance instead of issubclass The remaining function bytes_from_int() has been moved to utils.py.
* Fix `tox -e lint` warnings and errors (#490)Jon Dufresne2020-06-091-15/+13
| | | Now successfully passes when running `tox -e lint`.
* Run pyupgrade across project to use modern Python 3 conventions (#491)Jon Dufresne2020-06-081-5/+3
| | | | | | | | pyupgrade is a tool to automatically upgrade Python syntax for newer versions of the language. Running pyupgrade removes several Python-2-isms that are no longer necessary now that the project is Python 3 only. https://github.com/asottile/pyupgrade
* Add support for Ed25519 / EdDSA, with unit tests (#455)Someguy1232020-05-241-0/+12
|
* DX Tweaks (#450)José Padilla2019-10-211-97/+154
| | | | | | | | | | * Setup pre-commit hooks * Run initial `tox -e lint` * Fix package name * Fix .travis.yml
* Require cryptography >= 1.4, replace deprecated functionRan Benita2017-08-251-42/+16
| | | | | The signer/verifier interfaces are deprecated in cryptography==2.0. The alternative sign/verify interfaces were added in cryptography==1.4.
* Throw if key is an PKCS1 PEM-encoded public keyJosé Padilla2017-06-221-0/+1
|
* Add support for public keys in OpenSSH (RFC 4253) format.Mark Adams2017-03-141-1/+4
| | | | | | | | Cryptography previously lacked support for ECDSA keys in RFC 4253 format. Now that they have support for those keys, we should take advantage of it and support them in PyJWT. Implements #243.
* python2.6 does not support set literalsLandon GB2016-11-301-2/+2
|
* Changes per code reviewLandon GB2016-11-301-39/+14
|
* Fix all flake8 issues tox is complaining aboutLandon GB2016-11-281-2/+1
|
* Removing accidently comma (no, this shouldn't be a tupple)Landon GB2016-11-281-1/+1
|
* Merge remote-tracking branch 'upstream/master'Landon GB2016-11-281-14/+146
|\
| * Add back 'ES512' for backward compatibility (for now)ecdsa-bkwards-compatMark Adams2016-10-241-0/+1
| |
| * Merge pull request #219 from mike9005/es521_fixMark Adams2016-10-241-1/+1
| |\ | | | | | | Fix incorrectly named ECDSA algorithm
| | * Fix typo in AlgorithmsMichael Collis2016-09-211-1/+1
| | |
| * | Add JWK support for HMAC and RSA keysadd-jwk-for-hmac-rsaMark Adams2016-08-281-14/+144
| |/ | | | | | | | | | | | | - JWKs for RSA and HMAC can be encoded / decoded using the .to_jwk() and .from_jwk() methods on their respective jwt.algorithms instances - Replaced tests.utils ensure_unicode and ensure_bytes with jwt.utils versions
* | Better error messages when missing cryptography packageLandon GB2016-11-281-11/+40
|/
* Fix a bug where a PEM private key as bytes raises a TypeErrorfix-type-error-on-bytes-keyMark Adams2016-08-041-7/+7
|