def decrypt_key(key, interactive=True): try: return keypacket.parse(key, "") except keypacket.Error: pass while True: try: if interactive: p = passphrase.get_passphrase(confirm=False) else: print "Passphrase: " p = sys.stdin.readline().strip() return keypacket.parse(key, p) except keypacket.Error: if not interactive: print >> sys.stderr, "Incorrect passphrase" sys.exit(ExitCode.BADPASSPHRASE) print >> sys.stderr, "Incorrect passphrase, try again"
def key_has_passphrase(key): try: keypacket.parse(key, "") return False except keypacket.Error: return True