@@ -582,8 +582,7 @@ def enc_setup(self, msg, auth_data, key=None, **kwargs):
582582 # Generate an ephemeral key pair if none is given
583583 curve = NISTEllipticCurve .by_name (key .crv )
584584 if "epk" in kwargs :
585- epk = kwargs ["epk" ] if isinstance (kwargs ["epk" ], ECKey ) else ECKey (
586- kwargs ["epk" ])
585+ epk = kwargs ["epk" ] if isinstance (kwargs ["epk" ], ECKey ) else ECKey (kwargs ["epk" ])
587586 else :
588587 raise Exception (
589588 "Ephemeral Public Key (EPK) Required for ECDH-ES JWE "
@@ -592,7 +591,7 @@ def enc_setup(self, msg, auth_data, key=None, **kwargs):
592591 params = {
593592 "apu" : b64e (apu ),
594593 "apv" : b64e (apv ),
595- "epk" : key .serialize (False )
594+ "epk" : epk .serialize (False )
596595 }
597596
598597 cek = iv = None
@@ -602,19 +601,20 @@ def enc_setup(self, msg, auth_data, key=None, **kwargs):
602601 iv = kwargs ['iv' ]
603602
604603 cek , iv = self ._generate_key_and_iv (self .enc , cek = cek , iv = iv )
604+
605605 if self .alg == "ECDH-ES" :
606606 try :
607607 dk_len = KEYLEN [self .enc ]
608608 except KeyError :
609609 raise Exception (
610610 "Unknown key length for algorithm %s" % self .enc )
611611
612- cek = ecdh_derive_key (curve , key .d , (epk .x , epk .y ), apu , apv ,
612+ cek = ecdh_derive_key (curve , epk .d , (key .x , key .y ), apu , apv ,
613613 str (self .enc ).encode (), dk_len )
614614 elif self .alg in ["ECDH-ES+A128KW" , "ECDH-ES+A192KW" , "ECDH-ES+A256KW" ]:
615615 _pre , _post = self .alg .split ("+" )
616616 klen = int (_post [1 :4 ])
617- kek = ecdh_derive_key (curve , key .d , (epk .x , epk .y ), apu , apv ,
617+ kek = ecdh_derive_key (curve , epk .d , (key .x , key .y ), apu , apv ,
618618 str (_post ).encode (), klen )
619619 encrypted_key = aes_wrap_key (kek , cek )
620620 else :
@@ -631,8 +631,7 @@ def dec_setup(self, token, key=None, **kwargs):
631631
632632 # Handle EPK / Curve
633633 if "epk" not in self .headers or "crv" not in self .headers ["epk" ]:
634- raise Exception (
635- "Ephemeral Public Key Missing in ECDH-ES Computation" )
634+ raise Exception ("Ephemeral Public Key Missing in ECDH-ES Computation" )
636635
637636 epubkey = ECKey (** self .headers ["epk" ])
638637 apu = apv = ""
@@ -759,8 +758,7 @@ def encrypt(self, keys=None, cek="", iv="", **kwargs):
759758
760759 if not keys :
761760 logger .error (
762- "Could not find any suitable encryption key for alg='{"
763- "}'" .format (_alg ))
761+ "Could not find any suitable encryption key for alg='{}'" .format (_alg ))
764762 raise NoSuitableEncryptionKey (_alg )
765763
766764 # Determine Encryption Class by Algorithm
0 commit comments