This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=83d6b2ab2dc5a3d257afb5f38debdcb092b4e811 commit 83d6b2ab2dc5a3d257afb5f38debdcb092b4e811 Author: Guillem Jover <guil...@debian.org> AuthorDate: Fri Jul 22 02:25:15 2022 +0200 Dpkg::OpenPGP: Refactor armoring code into an armor() function We need to armor some files, and this will make it possible to move out the openpgp_sig_to_asc() function from this module, where it does not really fit as it encodes policy that is not generally useful. --- scripts/Dpkg/OpenPGP.pm | 22 +++++++++++++++------- scripts/t/Dpkg_OpenPGP.t | 7 ++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/Dpkg/OpenPGP.pm b/scripts/Dpkg/OpenPGP.pm index 5e9e634d9..35594b37b 100644 --- a/scripts/Dpkg/OpenPGP.pm +++ b/scripts/Dpkg/OpenPGP.pm @@ -50,7 +50,7 @@ sub is_armored { } sub _gpg_armor { - my ($sig, $asc) = @_; + my ($type, $sig, $asc) = @_; my @gpg_opts = qw(--no-options); @@ -62,7 +62,7 @@ sub _gpg_armor { next if $line =~ m/^Version: /; next if $line =~ m/^Comment: /; - $line =~ s/ARMORED FILE/SIGNATURE/; + $line =~ s/ARMORED FILE/$type/; print { $fh_asc } $line; } @@ -73,6 +73,18 @@ sub _gpg_armor { return $asc; } +sub armor { + my ($type, $bin, $asc) = @_; + + if (find_command('gpg')) { + return _gpg_armor($type, $bin, $asc); + } else { + warning(g_('cannot OpenPGP ASCII armor signature file due to missing gpg')); + } + + return; +} + sub openpgp_sig_to_asc { my ($sig, $asc) = @_; @@ -84,11 +96,7 @@ sub openpgp_sig_to_asc return $asc; } - if (find_command('gpg')) { - return _gpg_armor($sig, $asc); - } else { - warning(g_('cannot OpenPGP ASCII armor signature file due to missing gpg')); - } + return armor('SIGNATURE', $sig, $asc); } return; diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t index 214212f87..9ed4de716 100644 --- a/scripts/t/Dpkg_OpenPGP.t +++ b/scripts/t/Dpkg_OpenPGP.t @@ -25,7 +25,7 @@ use Dpkg::ErrorHandling; test_needs_command('gpg'); -plan tests => 8; +plan tests => 9; use_ok('Dpkg::OpenPGP'); @@ -42,6 +42,11 @@ $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/data-file.asc"; + +Dpkg::OpenPGP::armor('ARMORED FILE', $binfile, $ascfile); +ok(compare($ascfile, $reffile) == 0, 'armor binary file into OpenPGP ASCII Armor'); + $ascfile = "$tmpdir/package_1.0.orig.tar.enoent"; is(openpgp_sig_to_asc("$datadir/nonexistent", $ascfile), undef, 'no conversion of inexistent file'); -- Dpkg.Org's dpkg