This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=b51030bd7d72614b8b66204afbd86047c0538039

commit b51030bd7d72614b8b66204afbd86047c0538039 (HEAD -> master)
Author: Guillem Jover <[email protected]>
AuthorDate: Thu Nov 12 13:54:48 2020 +0100

    Dpkg::OpenPGP: Refactor gpg armor code into its own function
---
 scripts/Dpkg/OpenPGP.pm | 48 +++++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/scripts/Dpkg/OpenPGP.pm b/scripts/Dpkg/OpenPGP.pm
index cf1b46610..79840a026 100644
--- a/scripts/Dpkg/OpenPGP.pm
+++ b/scripts/Dpkg/OpenPGP.pm
@@ -33,6 +33,30 @@ our @EXPORT = qw(
     openpgp_sig_to_asc
 );
 
+sub _armor_gpg {
+    my ($sig, $asc) = @_;
+
+    my @gpg_opts = qw(--no-options);
+
+    open my $fh_asc, '>', $asc
+        or syserr(g_('cannot create signature file %s'), $asc);
+    open my $fh_gpg, '-|', 'gpg', @gpg_opts, '-o', '-', '--enarmor', $sig
+        or syserr(g_('cannot execute %s program'), 'gpg');
+    while (my $line = <$fh_gpg>) {
+        next if $line =~ m/^Version: /;
+        next if $line =~ m/^Comment: /;
+
+        $line =~ s/ARMORED FILE/SIGNATURE/;
+
+        print { $fh_asc } $line;
+    }
+
+    close $fh_gpg or subprocerr('gpg');
+    close $fh_asc or syserr(g_('cannot write signature file %s'), $asc);
+
+    return $asc;
+}
+
 sub openpgp_sig_to_asc
 {
     my ($sig, $asc) = @_;
@@ -55,29 +79,11 @@ sub openpgp_sig_to_asc
             return $asc;
         }
 
-        if (not find_command('gpg')) {
+        if (find_command('gpg')) {
+            return _armor_gpg($sig, $asc);
+        } else {
             warning(g_('cannot OpenPGP ASCII armor signature file due to 
missing gpg'));
         }
-
-        my @gpg_opts = qw(--no-options);
-
-        open my $fh_asc, '>', $asc
-            or syserr(g_('cannot create signature file %s'), $asc);
-        open my $fh_gpg, '-|', 'gpg', @gpg_opts, '-o', '-', '--enarmor', $sig
-            or syserr(g_('cannot execute %s program'), 'gpg');
-        while (my $line = <$fh_gpg>) {
-            next if $line =~ m/^Version: /;
-            next if $line =~ m/^Comment: /;
-
-            $line =~ s/ARMORED FILE/SIGNATURE/;
-
-            print { $fh_asc } $line;
-        }
-
-        close $fh_gpg or subprocerr('gpg');
-        close $fh_asc or syserr(g_('cannot write signature file %s'), $asc);
-
-        return $asc;
     }
 
     return;

-- 
Dpkg.Org's dpkg

Reply via email to