@@ -387,9 +387,9 @@ def _decrypt(enc, key, ctxt, auth_data, iv, tag):
387387 try :
388388 text = gcm .decrypt (bytes_to_long (iv ), ctxt , bytes_to_long (tag ),
389389 auth_data )
390- return text , True
390+ return text
391391 except DecryptionFailed :
392- return None , False
392+ raise
393393 elif enc in ["A128CBC-HS256" , "A192CBC-HS384" , "A256CBC-HS512" ]:
394394 return aes_cbc_hmac_decrypt (key , iv , auth_data , ctxt , tag )
395395 else :
@@ -563,12 +563,10 @@ def decrypt(self, token, key, cek=None):
563563 except AssertionError :
564564 raise NotSupportedAlgorithm (enc )
565565
566- msg , flag = self ._decrypt (enc , cek , jwe .ciphertext (),
567- jwe .b64_protected_header (),
568- jwe .initialization_vector (),
569- jwe .authentication_tag ())
570- if flag is False :
571- raise DecryptionFailed ()
566+ msg = self ._decrypt (enc , cek , jwe .ciphertext (),
567+ jwe .b64_protected_header (),
568+ jwe .initialization_vector (),
569+ jwe .authentication_tag ())
572570
573571 if "zip" in jwe .headers and jwe .headers ["zip" ] == "DEF" :
574572 msg = zlib .decompress (msg )
@@ -603,7 +601,8 @@ def enc_setup(self, msg, auth_data, key=None, **kwargs):
603601 # Generate an ephemeral key pair if none is given
604602 curve = NISTEllipticCurve .by_name (key .crv )
605603 if "epk" in kwargs :
606- epk = kwargs ["epk" ] if isinstance (kwargs ["epk" ], ECKey ) else ECKey (kwargs ["epk" ])
604+ epk = kwargs ["epk" ] if isinstance (kwargs ["epk" ], ECKey ) else ECKey (
605+ kwargs ["epk" ])
607606 else :
608607 epk = ECKey ().load_key (key = NISTEllipticCurve .by_name (key .crv ))
609608
@@ -650,7 +649,8 @@ def dec_setup(self, token, key=None, **kwargs):
650649
651650 # Handle EPK / Curve
652651 if "epk" not in self .headers or "crv" not in self .headers ["epk" ]:
653- raise Exception ("Ephemeral Public Key Missing in ECDH-ES Computation" )
652+ raise Exception (
653+ "Ephemeral Public Key Missing in ECDH-ES Computation" )
654654
655655 epubkey = ECKey (** self .headers ["epk" ])
656656 apu = apv = ""
@@ -716,12 +716,12 @@ def decrypt(self, token=None, key=None, **kwargs):
716716 if not self .cek :
717717 raise Exception ("Content Encryption Key is Not Yet Set" )
718718
719- msg , valid = super (JWE_EC , self )._decrypt (self .headers ["enc" ], self .cek ,
720- self .ctxt ,
721- jwe .b64part [0 ],
722- self .iv , self .tag )
719+ msg = super (JWE_EC , self )._decrypt (self .headers ["enc" ], self .cek ,
720+ self .ctxt ,
721+ jwe .b64part [0 ],
722+ self .iv , self .tag )
723723 self .msg = msg
724- self .msg_valid = valid
724+ self .msg_valid = True
725725 return msg
726726
727727
@@ -782,7 +782,9 @@ def encrypt(self, keys=None, cek="", iv="", **kwargs):
782782
783783 if not keys :
784784 logger .error (
785- "Could not find any suitable encryption key for alg='{}'" .format (_alg ))
785+ "Could not find any suitable encryption key for alg='{"
786+ "}'" .format (
787+ _alg ))
786788 raise NoSuitableEncryptionKey (_alg )
787789
788790 # Determine Encryption Class by Algorithm
0 commit comments