Skip to content
Snippets Groups Projects
Commit 816b7847 authored by Guillem Jover's avatar Guillem Jover
Browse files

Dpkg::OpenPGP: Refactor _gpg_import_keys() out of import_key()

parent d861e635
No related branches found
No related tags found
1 merge request!4Update crimson to version from bookworm
......@@ -109,32 +109,38 @@ sub _exec_openpgp
}
}
sub _gpg_import_keys {
my ($opts, $keyring, @keys) = @_;
my $gpghome = File::Temp->newdir('dpkg-gpg-import-keys.XXXXXXXX', TMPDIR => 1);
my @exec = qw(gpg);
push @exec, '--homedir', $gpghome;
push @exec, '--no-options', '--no-default-keyring', '-q', '--import';
push @exec, '--keyring', $keyring;
foreach my $key (@keys) {
my $errmsg = sprintf g_('cannot import key %s into %s'), $key, $keyring;
_exec_openpgp($opts, [ @exec, $key ], $errmsg);
}
}
sub import_key {
my ($opts, $asc) = @_;
$opts->{require_valid_signature} //= 1;
my @exec;
if (find_command('gpg')) {
push @exec, 'gpg';
_gpg_import_keys($opts, $opts->{keyring}, $asc);
} elsif ($opts->{require_valid_signature}) {
error(g_('cannot import key in %s since GnuPG is not installed'),
$asc);
} else {
warning(g_('cannot import key in %s since GnuPG is not installed'),
$asc);
return;
}
my $gpghome = File::Temp->newdir('dpkg-import-key.XXXXXXXX', TMPDIR => 1);
push @exec, '--homedir', $gpghome;
push @exec, '--no-options', '--no-default-keyring', '-q', '--import';
push @exec, '--keyring', $opts->{keyring};
push @exec, $asc;
my $errmsg = sprintf g_('cannot import key %s into %s'), $asc, $opts->{keyring};
_exec_openpgp($opts, \@exec, $errmsg);
return;
}
sub verify_signature {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment