Skip to content

Commit ae36ce3

Browse files
authored
v0.8.0
* BREAKING CHANGE: rename all `jwk` parameters to `key`, since they can accept any `cryptography` key instance * add `Jwt.sign_arbitrary()` * updated deps * move SymmetricJwk specific code from `Jwk.generate()` to `SymmetricJwk.generate()` * JwsCompact.from_parts() doesn't accept a str as signature anymore
1 parent f3795a6 commit ae36ce3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2060
-1907
lines changed

.github/workflows/dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install dependencies
3636
run: |
3737
python -m pip install --upgrade pip
38-
pip install poetry "tox<4" tox-gh-actions tox-poetry
38+
pip install poetry tox tox-gh-actions
3939
4040
- name: test with tox
4141
run:
@@ -62,7 +62,7 @@ jobs:
6262
- name: Install dependencies
6363
run: |
6464
python -m pip install --upgrade pip
65-
pip install poetry "tox<4" tox-gh-actions tox-poetry
65+
pip install poetry tox tox-gh-actions
6666
6767
- name: test with tox
6868
run:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
# This workflow contains a single job called "build"
1919
release:
2020
name: Create Release
21-
runs-on: ubuntu-20.04
21+
runs-on: ubuntu-22.04
2222

2323
strategy:
2424
matrix:

.pre-commit-config.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ repos:
2323
- id: python-use-type-annotations
2424
- id: text-unicode-replacement-char
2525
- repo: https://github.com/myint/docformatter
26-
rev: v1.6.5
26+
rev: v1.7.2
2727
hooks:
2828
- id: docformatter
2929
args:
3030
- --in-place
3131
- --wrap-summaries=100
3232
- --wrap-descriptions=100
3333
- repo: https://github.com/hadialqattan/pycln
34-
rev: v2.1.3
34+
rev: v2.1.5
3535
hooks:
3636
- id: pycln
3737
args: [--config=pyproject.toml]
@@ -50,7 +50,7 @@ repos:
5050
additional_dependencies:
5151
- flake8-typing-imports==1.14.0
5252
- repo: https://github.com/asottile/blacken-docs
53-
rev: 1.13.0
53+
rev: 1.14.0
5454
hooks:
5555
- id: blacken-docs
5656
- repo: https://github.com/pycqa/pydocstyle
@@ -62,10 +62,15 @@ repos:
6262
args:
6363
- --add-ignore=D107
6464
- repo: https://github.com/pre-commit/mirrors-mypy
65-
rev: v1.3.0
65+
rev: v1.4.0
6666
hooks:
6767
- id: mypy
68-
args: [--strict]
68+
args:
69+
- --strict
70+
- --implicit-reexport
71+
- --show-error-codes
72+
- --show-error-context
73+
- --show-column-numbers
6974
additional_dependencies:
7075
- types-cryptography==3.3.23.2
7176
- pytest-mypy==0.10.3

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# History
2+
## 0.8.0 (2023-06-21)
3+
- BREAKING CHANGE: all method parameters `jwk`, `sig_jwk`, `enc_jwk`, or `jwk_or_password`, accepting a `Jwk` instance
4+
have been renamed to `key` or `sig_key`,`enc_key` or `key_or_password` respectively.
5+
They now accept either a `Jwk` instance, or a dict containing a JWK, or a `cryptography` key instance directly.
6+
- Added `Jwt.sign_arbitrary()` to sign JWT with arbitrary headers, for testing purposes only!
7+
- Updated dev dependencies
28

39
## 0.1.0 (2021-11-15)
410

jwskate/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This module contains enums for the various identifiers used in JWA and JWK.
22
33
See [IANA JOSE](https://www.iana.org/assignments/jose/jose.xhtml).
4+
45
"""
56

67

jwskate/jwa/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
`cryptography`.
66
77
[RFC7518]: https://www.rfc-editor.org/rfc/rfc7518
8+
89
"""
910

1011
from .base import (

jwskate/jwa/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class BaseAlg:
2525
An algorithm has a `name` and a `description`, whose reference is found in [IANA JOSE registry][IANA].
2626
2727
[IANA]: https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms
28+
2829
"""
2930

3031
use: str
@@ -53,6 +54,7 @@ class BaseSymmetricAlg(BaseAlg):
5354
5455
Args:
5556
key: the key to use for cryptographic operations
57+
5658
"""
5759

5860
def __init__(self, key: bytes):
@@ -71,6 +73,7 @@ def check_key(cls, key: bytes) -> None:
7173
7274
Returns:
7375
Returns `None`. Raises an exception if the key is not suitable
76+
7477
"""
7578
pass
7679

@@ -105,6 +108,7 @@ class BaseAsymmetricAlg(Generic[Kpriv, Kpub], BaseAlg):
105108
106109
Args:
107110
key: the key to use.
111+
108112
"""
109113

110114
private_key_class: Union[Type[Kpriv], Tuple[Type[Kpriv], ...]]
@@ -128,6 +132,7 @@ def check_key(cls, key: Union[Kpriv, Kpub]) -> None:
128132
129133
Raises:
130134
Exception: if the key is not suitable for use with this alg class
135+
131136
"""
132137

133138
@contextmanager
@@ -139,6 +144,7 @@ def private_key_required(self) -> Iterator[Kpriv]:
139144
140145
Raises:
141146
PrivateKeyRequired: if the configured key is not private
147+
142148
"""
143149
if not isinstance(self.key, self.private_key_class):
144150
raise PrivateKeyRequired()
@@ -153,6 +159,7 @@ def public_key_required(self) -> Iterator[Kpub]:
153159
154160
Raises:
155161
PublicKeyRequired: if the configured key is private
162+
156163
"""
157164
if not isinstance(self.key, self.public_key_class):
158165
raise PublicKeyRequired()
@@ -184,6 +191,7 @@ def sign(self, data: Union[bytes, SupportsBytes]) -> BinaPy:
184191
185192
Returns:
186193
the raw signature
194+
187195
"""
188196
raise NotImplementedError
189197

@@ -198,6 +206,7 @@ def verify(
198206
199207
Returns:
200208
`True` if the signature matches, `False` otherwise.
209+
201210
"""
202211
raise NotImplementedError
203212

@@ -220,6 +229,7 @@ def check_key(cls, key: bytes) -> None:
220229
221230
Raises:
222231
ValueError: if the key is not suitable
232+
223233
"""
224234
if len(key) * 8 != cls.key_size:
225235
raise ValueError(
@@ -232,6 +242,7 @@ def generate_key(cls) -> BinaPy:
232242
233243
Returns:
234244
a random AES key
245+
235246
"""
236247
return BinaPy.random_bits(cls.key_size)
237248

@@ -241,6 +252,7 @@ def generate_iv(cls) -> BinaPy:
241252
242253
Returns:
243254
a random IV
255+
244256
"""
245257
return BinaPy.random_bits(cls.iv_size)
246258

@@ -268,6 +280,7 @@ def encrypt(
268280
269281
Returns:
270282
a tuple of ciphered data and authentication tag
283+
271284
"""
272285
raise NotImplementedError
273286

@@ -294,6 +307,7 @@ def decrypt(
294307
295308
Returns:
296309
the deciphered data
310+
297311
"""
298312
raise NotImplementedError
299313

@@ -304,6 +318,7 @@ def with_random_key(cls) -> Self:
304318
305319
Returns:
306320
a subclass of `BaseAESEncryptionAlg` initialized with a randomly generated key
321+
307322
"""
308323
return cls(cls.generate_key())
309324

jwskate/jwa/ec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class EllipticCurve:
1616
"""A descriptive class for Elliptic Curves.
1717
1818
Elliptic Curves have a name, a `cryptography.ec.EllipticCurve`, and a coordinate size.
19+
1920
"""
2021

2122
name: str
@@ -43,6 +44,7 @@ def generate(self) -> Tuple[int, int, int]:
4344
4445
Returns:
4546
a tuple of 4 `int`s: `x` and `y` coordinates (public key) and `d` (private key)
47+
4648
"""
4749
key = ec.generate_private_key(self.cryptography_curve)
4850
pn = key.private_numbers() # type: ignore[attr-defined]

jwskate/jwa/encryption/aescbchmac.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, key: bytes) -> None:
2929
3030
Args:
3131
key: the key to use for encryption and decryption.
32+
3233
"""
3334
super().__init__(key)
3435
self.mac_key = self.key[: self.mac_key_size // 8]
@@ -129,6 +130,7 @@ def decrypt(
129130
130131
Returns:
131132
the decrypted data
133+
132134
"""
133135
if not isinstance(ciphertext, bytes):
134136
ciphertext = bytes(ciphertext)

jwskate/jwa/encryption/aesgcm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def encrypt(
3434
3535
Raises:
3636
ValueError: if the IV size is not appropriate
37+
3738
"""
3839
if not isinstance(iv, bytes):
3940
iv = bytes(iv)
@@ -70,6 +71,7 @@ def decrypt(
7071
7172
Raises:
7273
ValueError: if the IV size is not appropriate
74+
7375
"""
7476
if not isinstance(ciphertext, bytes):
7577
ciphertext = bytes(ciphertext)

0 commit comments

Comments
 (0)