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

Dpkg::OpenPGP: Refactor is_armored() out from openpgp_sig_to_asc()

parent 280f64d6
No related branches found
No related tags found
1 merge request!4Update crimson to version from bookworm
......@@ -33,6 +33,22 @@ our @EXPORT = qw(
openpgp_sig_to_asc
);
sub is_armored {
my $file = shift;
my $armored = 0;
open my $fh, '<', $file or syserr(g_('cannot open %s'), $file);
while (<$fh>) {
if (m/^-----BEGIN PGP /) {
$armored = 1;
last;
}
}
close $fh;
return $armored;
}
sub _gpg_armor {
my ($sig, $asc) = @_;
......@@ -62,18 +78,7 @@ sub openpgp_sig_to_asc
my ($sig, $asc) = @_;
if (-e $sig) {
my $is_openpgp_ascii_armor = 0;
open my $fh_sig, '<', $sig or syserr(g_('cannot open %s'), $sig);
while (<$fh_sig>) {
if (m/^-----BEGIN PGP /) {
$is_openpgp_ascii_armor = 1;
last;
}
}
close $fh_sig;
if ($is_openpgp_ascii_armor) {
if (is_armored($sig)) {
notice(g_('signature file is already OpenPGP ASCII armor, copying'));
copy($sig, $asc);
return $asc;
......
......@@ -282,6 +282,8 @@ test_data = \
t/Dpkg_File/append-me \
t/Dpkg_File/dump-partial \
t/Dpkg_File/slurp-me \
t/Dpkg_OpenPGP/data-file \
t/Dpkg_OpenPGP/data-file.asc \
t/Dpkg_OpenPGP/package_1.0.orig.tar \
t/Dpkg_OpenPGP/package_1.0.orig.tar.asc \
t/Dpkg_OpenPGP/package_1.0.orig.tar.sig \
......
......@@ -25,7 +25,7 @@ use Dpkg::ErrorHandling;
test_needs_command('gpg');
plan tests => 6;
plan tests => 8;
use_ok('Dpkg::OpenPGP');
......@@ -33,7 +33,14 @@ report_options(quiet_warnings => 1);
my $datadir = test_get_data_path();
my $tmpdir = test_get_temp_path();
my $ascfile;
my ($reffile, $binfile, $ascfile);
$binfile = "$datadir/data-file";
$reffile = "$datadir/data-file.asc";
ok(!Dpkg::OpenPGP::is_armored($binfile), 'file not ASCII Armored');
ok(Dpkg::OpenPGP::is_armored($reffile), 'file ASCII Armored');
$ascfile = "$tmpdir/package_1.0.orig.tar.enoent";
is(openpgp_sig_to_asc("$datadir/nonexistent", $ascfile),
......
This is a data file that will be armored
as part of the dpkg OpenPGP test suite.
It contains «UTF-8» characters so that
we can check → non-ASCII Armor ☺.
-----BEGIN PGP ARMORED FILE-----
VGhpcyBpcyBhIGRhdGEgZmlsZSB0aGF0IHdpbGwgYmUgYXJtb3JlZAphcyBwYXJ0
IG9mIHRoZSBkcGtnIE9wZW5QR1AgdGVzdCBzdWl0ZS4KCkl0IGNvbnRhaW5zIMKr
VVRGLTjCuyBjaGFyYWN0ZXJzIHNvIHRoYXQKd2UgY2FuIGNoZWNrIOKGkiBub24t
QVNDSUkgQXJtb3Ig4pi6Lgo=
=NrdA
-----END PGP ARMORED FILE-----
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