Skip to content

Commit

Permalink
use a better error message for missing sigs on clearsigned piped scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ellotheth committed Mar 19, 2016
1 parent d0f04ff commit 57a1eff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func main() {
// still happen.
defer func() {
if r := recover(); r != nil {
flag.Usage()
os.Exit(1)
}
}()
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 8 additions & 4 deletions signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -42,7 +46,7 @@ func (s Signature) Name() string {
// Source is the original location of the signature file. It defaults to
// <script source>.sig.
func (s *Signature) Source() string {
if s.source != "" || s.script == nil || s.script.clearsigned {
if s.source != "" || s.script == nil || s.script.IsClearsigned() {
return s.source
}

Expand All @@ -53,7 +57,7 @@ func (s *Signature) Source() string {

// Download saves the signature to a temporary file.
func (s *Signature) Download() error {
if s.script != nil && s.script.clearsigned {
if s.script != nil && s.script.IsClearsigned() {
return nil
}

Expand Down

0 comments on commit 57a1eff

Please sign in to comment.