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=3bdad83225dfa70a1de18dccafea6949f262c399

commit 3bdad83225dfa70a1de18dccafea6949f262c399
Author: Guillem Jover <[email protected]>
AuthorDate: Fri Jul 22 03:01:46 2022 +0200

    Dpkg::Source::Package: Add armor_original_tarball_signature() member
    
    Move the Dpkg::OpenPGP::openpgp_sig_to_asc() function into a
    Dpkg::Source::Package member function as that has policy logic that
    does not really belong in the more generic Dpkg::OpenPGP module.
---
 scripts/Dpkg/OpenPGP.pm                            |  22 -----------
 scripts/Dpkg/Source/Package.pm                     |  32 ++++++++++++++-
 scripts/Dpkg/Source/Package/V1.pm                  |   3 +-
 scripts/Dpkg/Source/Package/V2.pm                  |   3 +-
 scripts/Makefile.am                                |   6 +--
 scripts/t/Dpkg_OpenPGP.t                           |  23 +----------
 scripts/t/Dpkg_Source_Package.t                    |  44 +++++++++++++++++++--
 .../package_1.0.orig.tar                           |   0
 .../package_1.0.orig.tar.asc                       |   0
 .../package_1.0.orig.tar.sig                       | Bin
 10 files changed, 76 insertions(+), 57 deletions(-)

diff --git a/scripts/Dpkg/OpenPGP.pm b/scripts/Dpkg/OpenPGP.pm
index 35594b37b..53c2c9f58 100644
--- a/scripts/Dpkg/OpenPGP.pm
+++ b/scripts/Dpkg/OpenPGP.pm
@@ -19,9 +19,7 @@ use strict;
 use warnings;
 
 use POSIX qw(:sys_wait_h);
-use Exporter qw(import);
 use File::Temp;
-use File::Copy;
 
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
@@ -29,9 +27,6 @@ use Dpkg::IPC;
 use Dpkg::Path qw(find_command);
 
 our $VERSION = '0.01';
-our @EXPORT = qw(
-    openpgp_sig_to_asc
-);
 
 sub is_armored {
     my $file = shift;
@@ -85,23 +80,6 @@ sub armor {
     return;
 }
 
-sub openpgp_sig_to_asc
-{
-    my ($sig, $asc) = @_;
-
-    if (-e $sig) {
-        if (is_armored($sig)) {
-            notice(g_('signature file is already OpenPGP ASCII armor, 
copying'));
-            copy($sig, $asc);
-            return $asc;
-        }
-
-        return armor('SIGNATURE', $sig, $asc);
-    }
-
-    return;
-}
-
 sub _gpg_exec
 {
     my ($opts, $exec, $errmsg) = @_;
diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm
index e0208c507..0ac85990e 100644
--- a/scripts/Dpkg/Source/Package.pm
+++ b/scripts/Dpkg/Source/Package.pm
@@ -34,7 +34,7 @@ is the one that supports the extraction of the source package.
 use strict;
 use warnings;
 
-our $VERSION = '2.01';
+our $VERSION = '2.02';
 our @EXPORT_OK = qw(
     get_default_diff_ignore_regex
     set_default_diff_ignore_regex
@@ -45,7 +45,7 @@ use Exporter qw(import);
 use POSIX qw(:errno_h :sys_wait_h);
 use Carp;
 use File::Temp;
-use File::Copy qw(cp);
+use File::Copy qw(cp copy);
 use File::Basename;
 use File::Spec;
 
@@ -417,6 +417,30 @@ sub get_upstream_signing_key {
     return "$dir/debian/upstream/signing-key.asc";
 }
 
+=item $p->armor_original_tarball_signature($bin, $asc)
+
+Convert a signature from binary to ASCII armored form. If the signature file
+does not exist, it is a no-op. If the signature file is already ASCII armored
+then simply copy it, otherwise convert it from binary to ASCII armored form.
+
+=cut
+
+sub armor_original_tarball_signature {
+    my ($self, $bin, $asc) = @_;
+
+    if (-e $bin) {
+        if (Dpkg::OpenPGP::is_armored($bin)) {
+            notice(g_('signature file is already OpenPGP ASCII armor, 
copying'));
+            copy($bin, $asc);
+            return $asc;
+        }
+
+        return Dpkg::OpenPGP::armor('SIGNATURE', $bin, $asc);
+    }
+
+    return;
+}
+
 =item $p->check_original_tarball_signature($dir, @asc)
 
 Verify the original upstream tarball signatures @asc using the upstream
@@ -681,6 +705,10 @@ sub write_dsc {
 
 =head1 CHANGES
 
+=head2 Version 2.02 (dpkg 1.21.10)
+
+New method: armor_original_tarball_signature().
+
 =head2 Version 2.01 (dpkg 1.20.1)
 
 New method: get_upstream_signing_key().
diff --git a/scripts/Dpkg/Source/Package/V1.pm 
b/scripts/Dpkg/Source/Package/V1.pm
index 931d094f7..237d1a40b 100644
--- a/scripts/Dpkg/Source/Package/V1.pm
+++ b/scripts/Dpkg/Source/Package/V1.pm
@@ -36,7 +36,6 @@ use Dpkg::Source::Patch;
 use Dpkg::Exit qw(push_exit_handler pop_exit_handler);
 use Dpkg::Source::Functions qw(erasedir);
 use Dpkg::Source::Package::V3::Native;
-use Dpkg::OpenPGP;
 
 use parent qw(Dpkg::Source::Package);
 
@@ -426,7 +425,7 @@ sub do_build {
     if ($tarname) {
         $self->add_file($tarname);
         if (-e "$tarname.sig" and not -e "$tarname.asc") {
-            openpgp_sig_to_asc("$tarname.sig", "$tarname.asc");
+            $self->armor_original_tarball_signature("$tarname.sig", 
"$tarname.asc");
         }
     }
     if ($tarsign and -e $tarsign) {
diff --git a/scripts/Dpkg/Source/Package/V2.pm 
b/scripts/Dpkg/Source/Package/V2.pm
index c5328fa03..171e45529 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -43,7 +43,6 @@ use Dpkg::Source::Functions qw(erasedir chmod_if_needed 
fs_time);
 use Dpkg::Vendor qw(run_vendor_hook);
 use Dpkg::Control;
 use Dpkg::Changelog::Parse;
-use Dpkg::OpenPGP;
 
 use parent qw(Dpkg::Source::Package);
 
@@ -421,7 +420,7 @@ sub _generate_patch {
 
         # Check for an upstream signature.
         if (-e "$file.sig" and not -e "$file.asc") {
-            openpgp_sig_to_asc("$file.sig", "$file.asc");
+            $self->armor_original_tarball_signature("$file.sig", "$file.asc");
         }
         if (-e "$file.asc") {
             push @origtarfiles, "$file.asc";
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 922515a2c..699993ec7 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -284,9 +284,6 @@ test_data = \
        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 \
        t/Dpkg_Shlibs/basictags.c \
        t/Dpkg_Shlibs/basictags.symbols \
        t/Dpkg_Shlibs/ld.so.conf \
@@ -330,6 +327,9 @@ test_data = \
        t/Dpkg_Source_Patch/index-inert.patch \
        t/Dpkg_Source_Patch/partial.patch \
        t/Dpkg_Source_Quilt/parse/debian/patches/series \
+       t/Dpkg_Source_Package/package_1.0.orig.tar \
+       t/Dpkg_Source_Package/package_1.0.orig.tar.asc \
+       t/Dpkg_Source_Package/package_1.0.orig.tar.sig \
        t/Dpkg_Substvars/substvars1 \
        t/Dpkg_Substvars/substvars2 \
        t/dpkg_buildpackage/test-source_0.dsc \
diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t
index 9ed4de716..234be750c 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 => 9;
+plan tests => 4;
 
 use_ok('Dpkg::OpenPGP');
 
@@ -47,27 +47,6 @@ $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');
-
-$ascfile = "$tmpdir/package_1.0.orig.tar.sig2asc";
-is(openpgp_sig_to_asc("$datadir/package_1.0.orig.tar.sig", $ascfile),
-   $ascfile, 'conversion from binary sig to armored asc');
-
-ok(compare($ascfile, "$datadir/package_1.0.orig.tar.asc") == 0,
-   'binary signature converted to OpenPGP ASCII Armor');
-
-# Grab the output messages.
-eval {
-    $ascfile = "$tmpdir/package_1.0.orig.tar.asc2asc";
-    is(openpgp_sig_to_asc("$datadir/package_1.0.orig.tar.asc", $ascfile),
-       $ascfile, 'copy instead of converting already armored input');
-};
-
-ok(compare($ascfile, "$datadir/package_1.0.orig.tar.asc") == 0,
-   'OpenPGP ASCII Armor copied to destination');
-
 # TODO: Add actual test cases.
 
 1;
diff --git a/scripts/t/Dpkg_Source_Package.t b/scripts/t/Dpkg_Source_Package.t
index dd2769920..641bc0010 100644
--- a/scripts/t/Dpkg_Source_Package.t
+++ b/scripts/t/Dpkg_Source_Package.t
@@ -16,11 +16,47 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More;
+use Test::Dpkg qw(:paths :needs);
 
-BEGIN {
-    use_ok('Dpkg::Source::Package');
-}
+use File::Compare;
+
+use Dpkg::ErrorHandling;
+
+test_needs_command('gpg');
+
+plan tests => 6;
+
+use_ok('Dpkg::Source::Package');
+
+report_options(quiet_warnings => 1);
+
+my $datadir = test_get_data_path();
+my $tmpdir = test_get_temp_path();
+my $ascfile;
+
+my $p = Dpkg::Source::Package->new();
+
+$ascfile = "$tmpdir/package_1.0.orig.tar.enoent";
+is($p->armor_original_tarball_signature("$datadir/nonexistent", $ascfile),
+   undef, 'no conversion of inexistent file');
+
+$ascfile = "$tmpdir/package_1.0.orig.tar.sig2asc";
+is($p->armor_original_tarball_signature("$datadir/package_1.0.orig.tar.sig", 
$ascfile),
+   $ascfile, 'conversion from binary sig to armored asc');
+
+ok(compare($ascfile, "$datadir/package_1.0.orig.tar.asc") == 0,
+   'binary signature converted to OpenPGP ASCII Armor');
+
+# Grab the output messages.
+eval {
+    $ascfile = "$tmpdir/package_1.0.orig.tar.asc2asc";
+    
is($p->armor_original_tarball_signature("$datadir/package_1.0.orig.tar.asc", 
$ascfile),
+       $ascfile, 'copy instead of converting already armored input');
+};
+
+ok(compare($ascfile, "$datadir/package_1.0.orig.tar.asc") == 0,
+   'OpenPGP ASCII Armor copied to destination');
 
 # TODO: Add actual test cases.
 
diff --git a/scripts/t/Dpkg_OpenPGP/package_1.0.orig.tar 
b/scripts/t/Dpkg_Source_Package/package_1.0.orig.tar
similarity index 100%
rename from scripts/t/Dpkg_OpenPGP/package_1.0.orig.tar
rename to scripts/t/Dpkg_Source_Package/package_1.0.orig.tar
diff --git a/scripts/t/Dpkg_OpenPGP/package_1.0.orig.tar.asc 
b/scripts/t/Dpkg_Source_Package/package_1.0.orig.tar.asc
similarity index 100%
rename from scripts/t/Dpkg_OpenPGP/package_1.0.orig.tar.asc
rename to scripts/t/Dpkg_Source_Package/package_1.0.orig.tar.asc
diff --git a/scripts/t/Dpkg_OpenPGP/package_1.0.orig.tar.sig 
b/scripts/t/Dpkg_Source_Package/package_1.0.orig.tar.sig
similarity index 100%
rename from scripts/t/Dpkg_OpenPGP/package_1.0.orig.tar.sig
rename to scripts/t/Dpkg_Source_Package/package_1.0.orig.tar.sig

-- 
Dpkg.Org's dpkg

Reply via email to