Skip to content

Commit 6fd8622

Browse files
committed
fix!: move JWSAlgModel, JWEEncModel, JWEZipModel to jwa module
1 parent 94c0140 commit 6fd8622

File tree

5 files changed

+52
-36
lines changed

5 files changed

+52
-36
lines changed

src/joserfc/jwa.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
from ._rfc7515.registry import JWSRegistry
2+
from ._rfc7515.model import JWSAlgModel
3+
from ._rfc7516.registry import JWERegistry
4+
from ._rfc7516.models import (
5+
JWEDirectEncryption,
6+
JWEKeyEncryption,
7+
JWEKeyWrapping,
8+
JWEKeyAgreement,
9+
JWEAlgModel,
10+
JWEEncModel,
11+
JWEZipModel,
12+
)
113
from ._rfc7518.jws_algs import (
214
NoneAlgorithm,
315
HMACAlgorithm,
@@ -25,10 +37,12 @@
2537
)
2638
from ._rfc8037.jws_eddsa import EdDSA, EdDSAAlgorithm
2739
from ._rfc8812 import ES256K
40+
from ._keys import KeySet
2841

2942
__all__ = [
3043
# JWS algorithms
3144
"JWS_ALGORITHMS",
45+
"JWSAlgModel",
3246
"NoneAlgorithm",
3347
"HMACAlgorithm",
3448
"RSAAlgorithm",
@@ -39,18 +53,46 @@
3953
"JWE_ALG_MODELS",
4054
"JWE_ENC_MODELS",
4155
"JWE_ZIP_MODELS",
56+
"JWEAlgModel",
57+
"JWEDirectEncryption",
58+
"JWEKeyEncryption",
59+
"JWEKeyWrapping",
60+
"JWEKeyAgreement",
4261
"DirectAlgEncryption",
4362
"AESAlgKeyWrapping",
4463
"ECDHESAlgKeyAgreement",
4564
"AESGCMAlgKeyWrapping",
4665
"PBES2HSAlgKeyEncryption",
66+
"JWEEncModel",
4767
"CBCHS2EncModel",
4868
"GCMEncModel",
69+
"JWEZipModel",
4970
"DeflateZipModel",
71+
# setup methods
72+
"setup_jws_algorithms",
73+
"setup_jwe_algorithms",
5074
]
5175

5276
JWS_ALGORITHMS = [
5377
*_JWS_ALGORITHMS,
5478
EdDSA,
5579
ES256K,
5680
]
81+
82+
83+
def setup_jws_algorithms() -> None:
84+
for _alg in JWS_ALGORITHMS:
85+
JWSRegistry.register(_alg)
86+
KeySet.algorithm_keys[_alg.name] = [_alg.key_type]
87+
88+
89+
def setup_jwe_algorithms() -> None:
90+
for _alg in JWE_ALG_MODELS:
91+
KeySet.algorithm_keys[_alg.name] = _alg.key_types
92+
JWERegistry.register(_alg)
93+
94+
for _enc in JWE_ENC_MODELS:
95+
JWERegistry.register(_enc)
96+
97+
for _zip in JWE_ZIP_MODELS:
98+
JWERegistry.register(_zip)

src/joserfc/jwe.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
CompactEncryption as CompactEncryption,
1010
GeneralJSONEncryption as GeneralJSONEncryption,
1111
FlattenedJSONEncryption as FlattenedJSONEncryption,
12-
JWEEncModel,
13-
JWEZipModel,
1412
)
1513
from ._rfc7516.registry import (
1614
JWERegistry as JWERegistry,
@@ -24,7 +22,7 @@
2422
extract_general_json,
2523
extract_flattened_json,
2624
)
27-
from .jwa import JWE_ALG_MODELS, JWE_ENC_MODELS, JWE_ZIP_MODELS
25+
from .jwa import setup_jwe_algorithms
2826
from .jwk import Key, KeySet, ECKey, OKPKey, KeyFlexible, guess_key
2927
from .util import to_bytes
3028
from .registry import Header
@@ -35,8 +33,6 @@
3533
"FlattenedJSONSerialization",
3634
# modules
3735
"JWERegistry",
38-
"JWEEncModel",
39-
"JWEZipModel",
4036
"Recipient",
4137
"CompactEncryption",
4238
"GeneralJSONEncryption",
@@ -48,25 +44,8 @@
4844
"decrypt_json",
4945
# consts
5046
"default_registry",
51-
"JWE_ALG_MODELS",
52-
"JWE_ENC_MODELS",
53-
"JWE_ZIP_MODELS",
5447
]
55-
56-
57-
def __setup_jwe() -> None:
58-
for _alg in JWE_ALG_MODELS:
59-
KeySet.algorithm_keys[_alg.name] = _alg.key_types
60-
JWERegistry.register(_alg)
61-
62-
for _enc in JWE_ENC_MODELS:
63-
JWERegistry.register(_enc)
64-
65-
for _zip in JWE_ZIP_MODELS:
66-
JWERegistry.register(_zip)
67-
68-
69-
__setup_jwe()
48+
setup_jwe_algorithms()
7049

7150

7251
def encrypt_compact(

src/joserfc/jws.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ._rfc7515.registry import (
1111
JWSRegistry as JWSRegistry,
1212
construct_registry,
13+
default_registry,
1314
)
1415
from ._rfc7515.compact import (
1516
sign_compact,
@@ -39,8 +40,8 @@
3940
extract_rfc7797_json as extract_flattened_json,
4041
)
4142
from .errors import BadSignatureError, MissingKeyError
42-
from .jwk import Key, KeyFlexible, KeySet, guess_key
43-
from .jwa import JWS_ALGORITHMS
43+
from .jwk import Key, KeyFlexible, guess_key
44+
from .jwa import setup_jws_algorithms
4445
from .util import to_bytes
4546
from .registry import Header
4647

@@ -50,7 +51,6 @@
5051
"GeneralJSONSerialization",
5152
"FlattenedJSONSerialization",
5253
# modules
53-
"JWSAlgModel",
5454
"JWSRegistry",
5555
"HeaderMember",
5656
"CompactSignature",
@@ -64,16 +64,11 @@
6464
"serialize_json",
6565
"deserialize_json",
6666
"detach_content",
67+
# consts
68+
"default_registry",
6769
]
6870

69-
70-
def __setup_jws() -> None:
71-
for _alg in JWS_ALGORITHMS:
72-
JWSRegistry.register(_alg)
73-
KeySet.algorithm_keys[_alg.name] = [_alg.key_type]
74-
75-
76-
__setup_jws()
71+
setup_jws_algorithms()
7772

7873

7974
def serialize_compact(

tests/jwe/test_compact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
encrypt_compact,
55
decrypt_compact,
66
CompactEncryption,
7-
JWE_ENC_MODELS,
87
)
8+
from joserfc.jwa import JWE_ENC_MODELS
99
from joserfc.jwk import RSAKey, ECKey, OctKey, OKPKey, KeySet
1010
from joserfc.errors import (
1111
InvalidKeyLengthError,

tests/jwe/test_ecdh_1pu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
decrypt_compact,
77
encrypt_json,
88
decrypt_json,
9-
JWE_ENC_MODELS,
109
)
10+
from joserfc.jwa import JWE_ENC_MODELS
1111
from joserfc.jwk import KeySet
1212
from joserfc.errors import InvalidEncryptionAlgorithmError
1313
from joserfc.drafts.jwe_ecdh_1pu import JWE_ALG_MODELS, register_ecdh_1pu

0 commit comments

Comments
 (0)