From b7f74b4e55a342b4c58e32cca5441b50438707ca Mon Sep 17 00:00:00 2001 From: Don Kuntz Date: Wed, 16 Oct 2019 16:43:00 -0500 Subject: [PATCH] Allow GPGFinder to work with nonstandard GPG version strings Specifically, I have MacGPG installed instead of upstream GPG, which results in the version string reading gpg (GnuPG/MacGPG2) 2.2.17 instead of the expected gpg (GnuPG) 2.2.17 --- pgp/gnupg_finder.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pgp/gnupg_finder.go b/pgp/gnupg_finder.go index bb610c8a..ea813020 100644 --- a/pgp/gnupg_finder.go +++ b/pgp/gnupg_finder.go @@ -4,7 +4,6 @@ import ( "errors" "os/exec" "regexp" - "strings" ) // GPGVersion stores discovered GPG version @@ -52,7 +51,7 @@ func GPG1Finder() GPGFinder { return &pathGPGFinder{ gpgNames: []string{"gpg", "gpg1"}, gpgvNames: []string{"gpgv", "gpgv1"}, - expectedVersionSubstring: "(GnuPG) 1.", + expectedVersionSubstring: `\(GnuPG.*\) (1).(\d)`, errorMessage: "Couldn't find a suitable gpg executable. Make sure gnupg1 is available as either gpg(v) or gpg(v)1 in $PATH", } } @@ -62,7 +61,7 @@ func GPG2Finder() GPGFinder { return &pathGPGFinder{ gpgNames: []string{"gpg", "gpg2"}, gpgvNames: []string{"gpgv", "gpgv2"}, - expectedVersionSubstring: "(GnuPG) 2.", + expectedVersionSubstring: `\(GnuPG.*\) (2).(\d)`, errorMessage: "Couldn't find a suitable gpg executable. Make sure gnupg2 is available as either gpg(v) or gpg(v)2 in $PATH", } } @@ -134,10 +133,11 @@ func cliVersionCheck(cmd string, marker string) (result bool, version GPGVersion } strOutput := string(output) - result = strings.Contains(strOutput, marker) + regex := regexp.MustCompile(marker) version = GPG22xPlus - matches := gpgVersionRegex.FindStringSubmatch(strOutput) + matches := regex.FindStringSubmatch(strOutput) + result = (matches != nil) if matches != nil { if matches[1] == "1" { version = GPG1x