Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow GPGFinder to work with nonstandard GPG version strings #888

Merged
merged 3 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ List of contributors, in chronological order:
* Nabil Bendafi (https://github.com/nabilbendafi)
* Raphael Medaer (https://github.com/rmedaer)
* Raul Benencia (https://github.com/rul)
* Don Kuntz (https://github.com/dkuntz2)
12 changes: 5 additions & 7 deletions pgp/gnupg_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"os/exec"
"regexp"
"strings"
)

// GPGVersion stores discovered GPG version
Expand All @@ -18,8 +17,6 @@ const (
GPG22xPlus GPGVersion = 4
)

var gpgVersionRegex = regexp.MustCompile(`\(GnuPG\) (\d)\.(\d)`)

// GPGFinder implement search for gpg executables and returns version of discovered executables
type GPGFinder interface {
FindGPG() (gpg string, version GPGVersion, err error)
Expand Down Expand Up @@ -52,7 +49,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",
}
}
Expand All @@ -62,7 +59,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",
}
}
Expand Down Expand Up @@ -134,10 +131,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
Expand Down