3434)
3535
3636
37- class DirectAlgModel (JWEDirectEncryption ):
37+ class DirectAlgEncryption (JWEDirectEncryption ):
3838 name = "dir"
3939 description = "Direct use of a shared symmetric key"
4040 recommended = True
@@ -49,7 +49,7 @@ def compute_cek(self, size: int, recipient: Recipient[OctKey]) -> bytes:
4949 return cek
5050
5151
52- class RSAAlgModel (JWEKeyEncryption ):
52+ class RSAAlgKeyEncryption (JWEKeyEncryption ):
5353 #: A key of size 2048 bits or larger MUST be used with these algorithms
5454 #: RSA1_5, RSA-OAEP, RSA-OAEP-256
5555 key_size = 2048
@@ -83,7 +83,7 @@ def decrypt_cek(self, recipient: Recipient[RSAKey]) -> bytes:
8383 return cek
8484
8585
86- class AESAlgModel (JWEKeyWrapping ):
86+ class AESAlgKeyWrapping (JWEKeyWrapping ):
8787 def __init__ (self , key_size : int , recommended : bool = False ):
8888 self .name = f"A{ key_size } KW"
8989 self .description = f"AES Key Wrap using { key_size } -bit key"
@@ -118,7 +118,7 @@ def decrypt_cek(self, recipient: Recipient[OctKey]) -> bytes:
118118 return self .unwrap_cek (recipient .encrypted_key , op_key )
119119
120120
121- class AESGCMAlgModel (JWEKeyWrapping ):
121+ class AESGCMAlgKeyWrapping (JWEKeyWrapping ):
122122 more_header_registry = {
123123 "iv" : HeaderParameter ("Initialization vector" , "str" , True ),
124124 "tag" : HeaderParameter ("Authentication tag" , "str" , True ),
@@ -179,7 +179,7 @@ def decrypt_cek(self, recipient: Recipient[OctKey]) -> bytes:
179179 return cek
180180
181181
182- class ECDHESAlgModel (JWEKeyAgreement ):
182+ class ECDHESAlgKeyAgreement (JWEKeyAgreement ):
183183 key_types = ["EC" , "OKP" ]
184184 more_header_registry = {
185185 "epk" : HeaderParameter ("Ephemeral Public Key" , "jwk" , True ),
@@ -225,7 +225,7 @@ def decrypt_agreed_upon_key(self, enc: JWEEncModel, recipient: Recipient[ECKey])
225225 return derive_key_for_concat_kdf (shared_key , headers , enc .cek_size , self .key_size )
226226
227227
228- class PBES2HSAlgModel (JWEKeyEncryption ):
228+ class PBES2HSAlgKeyEncryption (JWEKeyEncryption ):
229229 # https://www.rfc-editor.org/rfc/rfc7518#section-4.8
230230 key_size : int
231231 more_header_registry = {
@@ -293,40 +293,47 @@ def decrypt_cek(self, recipient: Recipient[OctKey]) -> bytes:
293293 return self .key_wrapping .unwrap_cek (recipient .encrypted_key , kek )
294294
295295
296- RSA1_5 = RSAAlgModel ("RSA1_5" , "RSAES-PKCS1-v1_5" , padding .PKCS1v15 ())
296+ RSA1_5 = RSAAlgKeyEncryption ("RSA1_5" , "RSAES-PKCS1-v1_5" , padding .PKCS1v15 ())
297297RSA1_5 .security_warning = 'JWE algorithm "RSA1_5" is deprecated, via draft-ietf-jose-deprecate-none-rsa15-02'
298298
299- A128KW = AESAlgModel (128 , True ) # A128KW, Recommended
300- A192KW = AESAlgModel (192 ) # A192KW
301- A256KW = AESAlgModel (256 , True ) # A256KW, Recommended
299+ A128KW = AESAlgKeyWrapping (128 , True ) # A128KW, Recommended
300+ A192KW = AESAlgKeyWrapping (192 ) # A192KW
301+ A256KW = AESAlgKeyWrapping (256 , True ) # A256KW, Recommended
302302
303303
304304#: https://www.rfc-editor.org/rfc/rfc7518#section-4.1
305305JWE_ALG_MODELS : list [JWEAlgModel ] = [
306306 RSA1_5 ,
307- RSAAlgModel (
307+ RSAAlgKeyEncryption (
308308 "RSA-OAEP" ,
309309 "RSAES OAEP using default parameters" ,
310310 padding .OAEP (padding .MGF1 (hashes .SHA1 ()), hashes .SHA1 (), None ),
311311 True ,
312312 ), # Recommended+
313- RSAAlgModel (
313+ RSAAlgKeyEncryption (
314314 "RSA-OAEP-256" ,
315315 "RSAES OAEP using SHA-256 and MGF1 with SHA-256" ,
316316 padding .OAEP (padding .MGF1 (hashes .SHA256 ()), hashes .SHA256 (), None ),
317317 ),
318318 A128KW ,
319319 A192KW ,
320320 A256KW ,
321- DirectAlgModel (), # dir, Recommended
322- ECDHESAlgModel (None ), # ECDH-ES, Recommended+
323- ECDHESAlgModel (A128KW ), # ECDH-ES+A128KW, Recommended
324- ECDHESAlgModel (A192KW ), # ECDH-ES+A192KW
325- ECDHESAlgModel (A256KW ), # ECDH-ES+A256KW, Recommended
326- AESGCMAlgModel (128 ), # A128GCMKW
327- AESGCMAlgModel (192 ), # A192GCMKW
328- AESGCMAlgModel (256 ), # A256GCMKW
329- PBES2HSAlgModel (256 , A128KW ), # PBES2-HS256+A128KW
330- PBES2HSAlgModel (384 , A192KW ), # PBES2-HS384+A192KW
331- PBES2HSAlgModel (512 , A256KW ), # PBES2-HS512+A256KW
321+ DirectAlgEncryption (), # dir, Recommended
322+ ECDHESAlgKeyAgreement (None ), # ECDH-ES, Recommended+
323+ ECDHESAlgKeyAgreement (A128KW ), # ECDH-ES+A128KW, Recommended
324+ ECDHESAlgKeyAgreement (A192KW ), # ECDH-ES+A192KW
325+ ECDHESAlgKeyAgreement (A256KW ), # ECDH-ES+A256KW, Recommended
326+ AESGCMAlgKeyWrapping (128 ), # A128GCMKW
327+ AESGCMAlgKeyWrapping (192 ), # A192GCMKW
328+ AESGCMAlgKeyWrapping (256 ), # A256GCMKW
329+ PBES2HSAlgKeyEncryption (256 , A128KW ), # PBES2-HS256+A128KW
330+ PBES2HSAlgKeyEncryption (384 , A192KW ), # PBES2-HS384+A192KW
331+ PBES2HSAlgKeyEncryption (512 , A256KW ), # PBES2-HS512+A256KW
332332]
333+
334+ # compatible alias
335+ DirectAlgModel = DirectAlgEncryption
336+ AESAlgModel = AESAlgKeyWrapping
337+ ECDHESAlgModel = ECDHESAlgKeyAgreement
338+ AESGCMAlgModel = AESGCMAlgKeyWrapping
339+ PBES2HSAlgModel = PBES2HSAlgKeyEncryption
0 commit comments