Skip to content

Commit fa0e059

Browse files
committed
openpgp: Raise an exception of importing yields no keys
Signed-off-by: Michał Górny <mgorny@gentoo.org>
1 parent 9e805b9 commit fa0e059

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

gemato/openpgp.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,15 @@ def import_key(self, keyfile, trust=True):
545545
keyfile.read(),
546546
raise_on_error=OpenPGPKeyImportError)
547547

548+
fprs = set()
549+
for line in out.splitlines():
550+
if line.startswith(b'[GNUPG:] IMPORT_OK'):
551+
fprs.add(line.split(b' ')[3].decode('ASCII'))
552+
if not fprs:
553+
raise OpenPGPKeyImportError("No keys imported")
554+
548555
if trust:
549-
fprs = set()
550-
for line in out.splitlines():
551-
if line.startswith(b'[GNUPG:] IMPORT_OK'):
552-
fprs.add(line.split(b' ')[3].decode('ASCII'))
553556
self._trusted_keys.update(fprs)
554-
555557
ownertrust = ''.join(f'{fpr}:6:\n' for fpr in fprs).encode('utf8')
556558
exitst, out, err = self._spawn_gpg(
557559
[GNUPG, '--batch', '--import-ownertrust'],

0 commit comments

Comments
 (0)