From 57a1eff0a85c134391816a634e1eab777773ff16 Mon Sep 17 00:00:00 2001 From: Gemma Lynn Date: Sat, 19 Mar 2016 11:25:32 -0600 Subject: [PATCH] use a better error message for missing sigs on clearsigned piped scripts --- main.go | 6 +++++- script.go | 6 ++++++ signature.go | 12 ++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index c89b34e..a697913 100644 --- a/main.go +++ b/main.go @@ -38,6 +38,7 @@ func main() { // still happen. defer func() { if r := recover(); r != nil { + flag.Usage() os.Exit(1) } }() @@ -91,7 +92,10 @@ func main() { log.Panic(err) } - signature := NewSignature(key, script, *sigSource) + signature, err := NewSignature(key, script, *sigSource) + if err != nil { + log.Panic(err) + } defer os.Remove(signature.Name()) if err := signature.Verify(); err != nil { diff --git a/script.go b/script.go index 9c56cda..6b04fee 100644 --- a/script.go +++ b/script.go @@ -205,3 +205,9 @@ func (s Script) Inspect(inspect bool, editor string) bool { return strings.ToLower(runScript) == "y" } + +// IsClearsigned returns true if the script and signature are attached, +// and false otherwise. +func (s Script) IsClearsigned() bool { + return s.clearsigned +} diff --git a/signature.go b/signature.go index 235b01e..c9f59a3 100644 --- a/signature.go +++ b/signature.go @@ -27,11 +27,15 @@ type Signature struct { } // NewSignature loads a key ring and Script into a new Signature. -func NewSignature(key openpgp.KeyRing, script *Script, source string) *Signature { +func NewSignature(key openpgp.KeyRing, script *Script, source string) (*Signature, error) { + if script.IsPiped() && !script.IsClearsigned() && source == "" { + return nil, errors.New("Your script is not clearsigned and you're piping from STDIN, so I need -signature.") + } + sig := &Signature{key: key, script: script, source: source} sig.filename = script.Name() + ".sig" - return sig + return sig, nil } // Name is the name of the temporary file holding the signature. @@ -42,7 +46,7 @@ func (s Signature) Name() string { // Source is the original location of the signature file. It defaults to //