Skip to content

Commit 07815f6

Browse files
enjoy black preview string formatting
1 parent b970d3e commit 07815f6

File tree

10 files changed

+447
-361
lines changed

10 files changed

+447
-361
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ repos:
2222
- --wrap-summaries=100
2323
- --wrap-descriptions=100
2424
- repo: https://github.com/psf/black
25-
rev: 23.7.0
25+
rev: 23.9.1
2626
hooks:
2727
- id: black
2828
- repo: https://github.com/asottile/blacken-docs
2929
rev: 1.16.0
3030
hooks:
3131
- id: blacken-docs
3232
- repo: https://github.com/astral-sh/ruff-pre-commit
33-
rev: v0.0.285
33+
rev: v0.0.291
3434
hooks:
3535
- id: ruff
3636
- repo: https://github.com/pre-commit/mirrors-mypy

jwskate/jwa/okp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def public_bytes( # noqa: D102
2222
self,
2323
encoding: serialization.Encoding,
2424
format: serialization.PublicFormat, # noqa: A002
25-
) -> bytes:
26-
...
25+
) -> bytes: ...
2726

2827

2928
@runtime_checkable
@@ -35,8 +34,7 @@ def private_bytes( # noqa: D102
3534
encoding: serialization.Encoding,
3635
format: serialization.PrivateFormat, # noqa: A002
3736
encryption_algorithm: serialization.KeySerializationEncryption,
38-
) -> bytes:
39-
...
37+
) -> bytes: ...
4038

4139
def public_key(self) -> PublicKeyProtocol: # noqa: D102
4240
...

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ all = [
133133

134134
[tool.black]
135135
line-length = 120
136+
preview = true
136137
include = '\.pyi?$'
137138
exclude = '''
138139
/(

tests/test_jwa/test_examples.py

Lines changed: 93 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,47 @@
88

99
def test_aes_128_hmac_sha256() -> None:
1010
"""Test derived from [RFC7518](https://datatracker.ietf.org/doc/html/rfc7518#appendix-B.1)."""
11-
key = bytes.fromhex(
12-
("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f" "10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f").replace(
13-
" ", ""
14-
)
15-
)
16-
mac_key = bytes.fromhex("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f".replace(" ", ""))
17-
enc_key = bytes.fromhex("10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f".replace(" ", ""))
18-
plaintext = bytes.fromhex(
19-
(
20-
"41 20 63 69 70 68 65 72 20 73 79 73 74 65 6d 20"
21-
"6d 75 73 74 20 6e 6f 74 20 62 65 20 72 65 71 75"
22-
"69 72 65 64 20 74 6f 20 62 65 20 73 65 63 72 65"
23-
"74 2c 20 61 6e 64 20 69 74 20 6d 75 73 74 20 62"
24-
"65 20 61 62 6c 65 20 74 6f 20 66 61 6c 6c 20 69"
25-
"6e 74 6f 20 74 68 65 20 68 61 6e 64 73 20 6f 66"
26-
"20 74 68 65 20 65 6e 65 6d 79 20 77 69 74 68 6f"
27-
"75 74 20 69 6e 63 6f 6e 76 65 6e 69 65 6e 63 65"
28-
).replace(" ", "")
29-
)
30-
iv = bytes.fromhex("1a f3 8c 2d c2 b9 6f fd d8 66 94 09 23 41 bc 04".replace(" ", ""))
31-
aad = bytes.fromhex(
32-
(
33-
"54 68 65 20 73 65 63 6f 6e 64 20 70 72 69 6e 63"
34-
"69 70 6c 65 20 6f 66 20 41 75 67 75 73 74 65 20"
35-
"4b 65 72 63 6b 68 6f 66 66 73"
36-
).replace(" ", "")
37-
)
38-
al = bytes.fromhex("00 00 00 00 00 00 01 50".replace(" ", "")) # noqa: F841
39-
ciphertext = bytes.fromhex(
40-
(
41-
"c8 0e df a3 2d df 39 d5 ef 00 c0 b4 68 83 42 79"
42-
"a2 e4 6a 1b 80 49 f7 92 f7 6b fe 54 b9 03 a9 c9"
43-
"a9 4a c9 b4 7a d2 65 5c 5f 10 f9 ae f7 14 27 e2"
44-
"fc 6f 9b 3f 39 9a 22 14 89 f1 63 62 c7 03 23 36"
45-
"09 d4 5a c6 98 64 e3 32 1c f8 29 35 ac 40 96 c8"
46-
"6e 13 33 14 c5 40 19 e8 ca 79 80 df a4 b9 cf 1b"
47-
"38 4c 48 6f 3a 54 c5 10 78 15 8e e5 d7 9d e5 9f"
48-
"bd 34 d8 48 b3 d6 95 50 a6 76 46 34 44 27 ad e5"
49-
"4b 88 51 ff b5 98 f7 f8 00 74 b9 47 3c 82 e2 db"
50-
).replace(" ", "")
51-
)
52-
53-
mac = bytes.fromhex( # noqa: F841
54-
("65 2c 3f a3 6b 0a 7c 5b 32 19 fa b3 a3 0b c1 c4" "e6 e5 45 82 47 65 15 f0 ad 9f 75 a2 b7 1c 73 ef").replace(
55-
" ", ""
56-
)
57-
)
58-
59-
tag = bytes.fromhex("65 2c 3f a3 6b 0a 7c 5b 32 19 fa b3 a3 0b c1 c4".replace(" ", ""))
11+
key = bytes.fromhex("""
12+
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
13+
10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
14+
""")
15+
mac_key = bytes.fromhex("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f")
16+
enc_key = bytes.fromhex("10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f")
17+
plaintext = bytes.fromhex("""
18+
41 20 63 69 70 68 65 72 20 73 79 73 74 65 6d 20
19+
6d 75 73 74 20 6e 6f 74 20 62 65 20 72 65 71 75
20+
69 72 65 64 20 74 6f 20 62 65 20 73 65 63 72 65
21+
74 2c 20 61 6e 64 20 69 74 20 6d 75 73 74 20 62
22+
65 20 61 62 6c 65 20 74 6f 20 66 61 6c 6c 20 69
23+
6e 74 6f 20 74 68 65 20 68 61 6e 64 73 20 6f 66
24+
20 74 68 65 20 65 6e 65 6d 79 20 77 69 74 68 6f
25+
75 74 20 69 6e 63 6f 6e 76 65 6e 69 65 6e 63 65
26+
""")
27+
iv = bytes.fromhex("1a f3 8c 2d c2 b9 6f fd d8 66 94 09 23 41 bc 04")
28+
aad = bytes.fromhex("""
29+
54 68 65 20 73 65 63 6f 6e 64 20 70 72 69 6e 63
30+
69 70 6c 65 20 6f 66 20 41 75 67 75 73 74 65 20
31+
4b 65 72 63 6b 68 6f 66 66 73
32+
""")
33+
al = bytes.fromhex("00 00 00 00 00 00 01 50")
34+
ciphertext = bytes.fromhex("""
35+
c8 0e df a3 2d df 39 d5 ef 00 c0 b4 68 83 42 79
36+
a2 e4 6a 1b 80 49 f7 92 f7 6b fe 54 b9 03 a9 c9
37+
a9 4a c9 b4 7a d2 65 5c 5f 10 f9 ae f7 14 27 e2
38+
fc 6f 9b 3f 39 9a 22 14 89 f1 63 62 c7 03 23 36
39+
09 d4 5a c6 98 64 e3 32 1c f8 29 35 ac 40 96 c8
40+
6e 13 33 14 c5 40 19 e8 ca 79 80 df a4 b9 cf 1b
41+
38 4c 48 6f 3a 54 c5 10 78 15 8e e5 d7 9d e5 9f
42+
bd 34 d8 48 b3 d6 95 50 a6 76 46 34 44 27 ad e5
43+
4b 88 51 ff b5 98 f7 f8 00 74 b9 47 3c 82 e2 db
44+
""")
45+
46+
mac = bytes.fromhex("""
47+
65 2c 3f a3 6b 0a 7c 5b 32 19 fa b3 a3 0b c1 c4
48+
e6 e5 45 82 47 65 15 f0 ad 9f 75 a2 b7 1c 73 ef
49+
""")
50+
51+
tag = bytes.fromhex("65 2c 3f a3 6b 0a 7c 5b 32 19 fa b3 a3 0b c1 c4")
6052

6153
cipher = A128CBC_HS256(key)
6254
assert cipher.aes_key == enc_key
@@ -68,63 +60,58 @@ def test_aes_128_hmac_sha256() -> None:
6860

6961
def test_aes_192_hmac_sha384() -> None:
7062
"""Test derived from [RFC7518](https://datatracker.ietf.org/doc/html/rfc7518#appendix-B.2)."""
71-
key = bytes.fromhex(
72-
(
73-
"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"
74-
"10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f"
75-
"20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f"
76-
).replace(" ", "")
77-
)
78-
mac_key = bytes.fromhex(
79-
("00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f" "10 11 12 13 14 15 16 17").replace(" ", "")
80-
)
81-
enc_key = bytes.fromhex(
82-
("18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27" "28 29 2a 2b 2c 2d 2e 2f").replace(" ", "")
83-
)
84-
plaintext = bytes.fromhex(
85-
(
86-
"41 20 63 69 70 68 65 72 20 73 79 73 74 65 6d 20"
87-
"6d 75 73 74 20 6e 6f 74 20 62 65 20 72 65 71 75"
88-
"69 72 65 64 20 74 6f 20 62 65 20 73 65 63 72 65"
89-
"74 2c 20 61 6e 64 20 69 74 20 6d 75 73 74 20 62"
90-
"65 20 61 62 6c 65 20 74 6f 20 66 61 6c 6c 20 69"
91-
"6e 74 6f 20 74 68 65 20 68 61 6e 64 73 20 6f 66"
92-
"20 74 68 65 20 65 6e 65 6d 79 20 77 69 74 68 6f"
93-
"75 74 20 69 6e 63 6f 6e 76 65 6e 69 65 6e 63 65"
94-
).replace(" ", "")
95-
)
96-
iv = bytes.fromhex("1a f3 8c 2d c2 b9 6f fd d8 66 94 09 23 41 bc 04".replace(" ", ""))
97-
aad = bytes.fromhex(
98-
(
99-
"54 68 65 20 73 65 63 6f 6e 64 20 70 72 69 6e 63"
100-
"69 70 6c 65 20 6f 66 20 41 75 67 75 73 74 65 20"
101-
"4b 65 72 63 6b 68 6f 66 66 73"
102-
).replace(" ", "")
103-
)
104-
al = bytes.fromhex("00 00 00 00 00 00 01 50".replace(" ", "")) # noqa: F841
105-
ciphertext = bytes.fromhex(
106-
(
107-
"ea 65 da 6b 59 e6 1e db 41 9b e6 2d 19 71 2a e5"
108-
"d3 03 ee b5 00 52 d0 df d6 69 7f 77 22 4c 8e db"
109-
"00 0d 27 9b dc 14 c1 07 26 54 bd 30 94 42 30 c6"
110-
"57 be d4 ca 0c 9f 4a 84 66 f2 2b 22 6d 17 46 21"
111-
"4b f8 cf c2 40 0a dd 9f 51 26 e4 79 66 3f c9 0b"
112-
"3b ed 78 7a 2f 0f fc bf 39 04 be 2a 64 1d 5c 21"
113-
"05 bf e5 91 ba e2 3b 1d 74 49 e5 32 ee f6 0a 9a"
114-
"c8 bb 6c 6b 01 d3 5d 49 78 7b cd 57 ef 48 49 27"
115-
"f2 80 ad c9 1a c0 c4 e7 9c 7b 11 ef c6 00 54 e3"
116-
).replace(" ", "")
117-
)
118-
119-
mac = bytes.fromhex( # noqa: F841
120-
(
121-
"84 90 ac 0e 58 94 9b fe 51 87 5d 73 3f 93 ac 20"
122-
"75 16 80 39 cc c7 33 d7 45 94 f8 86 b3 fa af d4"
123-
"86 f2 5c 71 31 e3 28 1e 36 c7 a2 d1 30 af de 57"
124-
).replace(" ", "")
125-
)
126-
127-
tag = bytes.fromhex(("84 90 ac 0e 58 94 9b fe 51 87 5d 73 3f 93 ac 20" "75 16 80 39 cc c7 33 d7").replace(" ", ""))
63+
key = bytes.fromhex("""
64+
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
65+
10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
66+
20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
67+
""")
68+
mac_key = bytes.fromhex("""
69+
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
70+
10 11 12 13 14 15 16 17
71+
""")
72+
enc_key = bytes.fromhex("""
73+
18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27
74+
28 29 2a 2b 2c 2d 2e 2f
75+
""")
76+
plaintext = bytes.fromhex("""
77+
41 20 63 69 70 68 65 72 20 73 79 73 74 65 6d 20
78+
6d 75 73 74 20 6e 6f 74 20 62 65 20 72 65 71 75
79+
69 72 65 64 20 74 6f 20 62 65 20 73 65 63 72 65
80+
74 2c 20 61 6e 64 20 69 74 20 6d 75 73 74 20 62
81+
65 20 61 62 6c 65 20 74 6f 20 66 61 6c 6c 20 69
82+
6e 74 6f 20 74 68 65 20 68 61 6e 64 73 20 6f 66
83+
20 74 68 65 20 65 6e 65 6d 79 20 77 69 74 68 6f
84+
75 74 20 69 6e 63 6f 6e 76 65 6e 69 65 6e 63 65
85+
""")
86+
iv = bytes.fromhex("1a f3 8c 2d c2 b9 6f fd d8 66 94 09 23 41 bc 04")
87+
aad = bytes.fromhex("""
88+
54 68 65 20 73 65 63 6f 6e 64 20 70 72 69 6e 63
89+
69 70 6c 65 20 6f 66 20 41 75 67 75 73 74 65 20
90+
4b 65 72 63 6b 68 6f 66 66 73
91+
""")
92+
al = bytes.fromhex("00 00 00 00 00 00 01 50") # noqa: F841
93+
ciphertext = bytes.fromhex("""
94+
ea 65 da 6b 59 e6 1e db 41 9b e6 2d 19 71 2a e5
95+
d3 03 ee b5 00 52 d0 df d6 69 7f 77 22 4c 8e db
96+
00 0d 27 9b dc 14 c1 07 26 54 bd 30 94 42 30 c6
97+
57 be d4 ca 0c 9f 4a 84 66 f2 2b 22 6d 17 46 21
98+
4b f8 cf c2 40 0a dd 9f 51 26 e4 79 66 3f c9 0b
99+
3b ed 78 7a 2f 0f fc bf 39 04 be 2a 64 1d 5c 21
100+
05 bf e5 91 ba e2 3b 1d 74 49 e5 32 ee f6 0a 9a
101+
c8 bb 6c 6b 01 d3 5d 49 78 7b cd 57 ef 48 49 27
102+
f2 80 ad c9 1a c0 c4 e7 9c 7b 11 ef c6 00 54 e3
103+
""")
104+
105+
mac = bytes.fromhex("""
106+
84 90 ac 0e 58 94 9b fe 51 87 5d 73 3f 93 ac 20
107+
75 16 80 39 cc c7 33 d7 45 94 f8 86 b3 fa af d4
108+
86 f2 5c 71 31 e3 28 1e 36 c7 a2 d1 30 af de 57
109+
""")
110+
111+
tag = bytes.fromhex("""
112+
84 90 ac 0e 58 94 9b fe 51 87 5d 73 3f 93 ac 20
113+
75 16 80 39 cc c7 33 d7
114+
""")
128115

129116
cipher = A192CBC_HS384(key)
130117
assert cipher.aes_key == enc_key

0 commit comments

Comments
 (0)