18
18
19
19
20
20
def encrypt (plaintext , key , encryption = ALGORITHMS .A256GCM ,
21
- algorithm = ALGORITHMS .DIR , zip = None , cty = None , kid = None ):
21
+ algorithm = ALGORITHMS .DIR , zip = None , cty = None , kid = None , headers = None ):
22
22
"""Encrypts plaintext and returns a JWE cmpact serialization string.
23
23
24
24
Args:
@@ -55,7 +55,7 @@ def encrypt(plaintext, key, encryption=ALGORITHMS.A256GCM,
55
55
if encryption not in ALGORITHMS .SUPPORTED :
56
56
raise JWEError ('Algorithm %s not supported.' % encryption )
57
57
key = jwk .construct (key , algorithm )
58
- encoded_header = _encoded_header (algorithm , encryption , zip , cty , kid )
58
+ encoded_header = _encoded_header (algorithm , encryption , zip , cty , kid , headers )
59
59
60
60
plaintext = _compress (zip , plaintext )
61
61
enc_cek , iv , cipher_text , auth_tag = _encrypt_and_auth (
@@ -335,7 +335,7 @@ def _jwe_compact_deserialize(jwe_bytes):
335
335
return header , header_segment , encrypted_key , iv , ciphertext , auth_tag
336
336
337
337
338
- def _encoded_header (alg , enc , zip , cty , kid ):
338
+ def _encoded_header (alg , enc , zip , cty , kid , headers ):
339
339
"""
340
340
Generate an appropriate JOSE header based on the values provided
341
341
Args:
@@ -355,6 +355,8 @@ def _encoded_header(alg, enc, zip, cty, kid):
355
355
header ["cty" ] = cty
356
356
if kid :
357
357
header ["kid" ] = kid
358
+ if headers :
359
+ header .update (headers )
358
360
json_header = json .dumps (
359
361
header ,
360
362
separators = (',' , ':' ),
0 commit comments