% type (tag))
data = self.enc.finalize_with_tag (self.tag)
except cryptography.exceptions.InvalidTag:
- raise InvalidGCMTag ("done: tag mismatch of object %d: %r "
+ raise InvalidGCMTag ("done: tag mismatch of object %d: %s "
"rejected by finalize ()"
- % (self.cnt, self.tag))
+ % (self.cnt, binascii.hexlify (self.tag)))
self.ctsize += len (data)
self.stats ["out"] += len (data)
return data
try:
pt = decr.done ()
except InvalidGCMTag as exn:
- raise DecryptionError ("error finalizing object (%s): %r"
- % (pt, exn))
+ raise DecryptionError ("error finalizing object %d (%d B): "
+ "%r" % (total_obj, len (pt), exn)) \
+ from exn
out (pt)
if PDTCRYPT_VERBOSE is True:
noise ("PDT:\t· object validated")
def main (argv):
pw, ins, outs = parse_argv (argv)
- total_read, total_obj, total_ct, total_pt = \
- depdtcrypt (pw, ins, outs)
+ try:
+ total_read, total_obj, total_ct, total_pt = \
+ depdtcrypt (pw, ins, outs)
+ except DecryptionError as exn:
+ noise ("PDT: Decryption failed:")
+ noise ("PDT:")
+ noise ("PDT: “%s”" % exn)
+ noise ("PDT:")
+ noise ("PDT: Did you specify the correct password?")
+ noise ("")
+ return 1
+
if PDTCRYPT_VERBOSE is True:
noise ("PDT: decryption successful" )
noise ("PDT: %.10d bytes read" % total_read)
noise ("PDT: %.10d bytes plaintext" % total_pt )
noise ("" )
+ return 0
+
if __name__ == "__main__":
sys.exit (main (sys.argv))