From 393f241538e340980a3f888e34e5c79253c68f4b Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 21 Jun 2022 03:03:23 -0400 Subject: [PATCH] Optimized decrypt() function (fixes issue #1) Former-commit-id: d94cce05e9695f4d0744b5a3f4232ad48b146ed2 [formerly 3ad5acfc99932608fcec33cc7223baac1dfb6314] Former-commit-id: b7edcf31903826ebb8010f6e694b728e1616a70f --- bin/sshyp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/sshyp b/bin/sshyp index 9cd7cff..9546d88 100755 --- a/bin/sshyp +++ b/bin/sshyp @@ -8,7 +8,7 @@ import random from shutil import get_terminal_size, move, rmtree import sshync import string -from subprocess import Popen, PIPE, STDOUT +from subprocess import CalledProcessError, Popen, PIPE, run, STDOUT from sys import argv, exit as s_exit from textwrap import fill @@ -155,9 +155,9 @@ def decrypt(_entry_dir, _shm_folder, _shm_entry): _command = f"{gpg} -qd --output /dev/null {path.expanduser('~/.config/sshyp/lock.gpg')}" else: _command = f"{gpg} -qd --output {tmp_dir}{_shm_folder}/{_shm_entry} {_entry_dir}.gpg" - _output = Popen(_command, shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True) - _block = _output.communicate()[0].strip() - if _output.returncode == 2: + try: + run(_command, shell=True, stderr=PIPE, check=True, close_fds=True) + except CalledProcessError: print(f"\n\u001b[38;5;9merror: could not decrypt - ensure the correct gpg key is present\u001b[0m\n") s_exit(1)