mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Rework Gpg signing to work through interface.
This commit is contained in:
47
utils/gpg.go
47
utils/gpg.go
@@ -1,20 +1,49 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GpgDetachedSign signs file with detached signature in ASCII format
|
||||
func GpgDetachedSign(source string, destination string) error {
|
||||
fmt.Printf("v = %#v\n", strings.Join([]string{"gpg", "-o", destination, "--armor", "--detach-sign", source}, " "))
|
||||
cmd := exec.Command("gpg", "-o", destination, "--armor", "--yes", "--detach-sign", source)
|
||||
// Signer interface describes facility implementing signing of files
|
||||
type Signer interface {
|
||||
SetKey(keyRef string)
|
||||
DetachedSign(source string, destination string) error
|
||||
ClearSign(source string, destination string) error
|
||||
}
|
||||
|
||||
// Test interface
|
||||
var (
|
||||
_ Signer = &GpgSigner{}
|
||||
)
|
||||
|
||||
// GpgSigner is implementation of Signer interface using gpg
|
||||
type GpgSigner struct {
|
||||
keyRef string
|
||||
}
|
||||
|
||||
// SetKey sets key ID to use when signing files
|
||||
func (g *GpgSigner) SetKey(keyRef string) {
|
||||
g.keyRef = keyRef
|
||||
}
|
||||
|
||||
// DetachedSign signs file with detached signature in ASCII format
|
||||
func (g *GpgSigner) DetachedSign(source string, destination string) error {
|
||||
args := []string{"-o", destination, "--armor", "--yes"}
|
||||
if g.keyRef != "" {
|
||||
args = append(args, "-u", g.keyRef)
|
||||
}
|
||||
args = append(args, "--detach-sign", source)
|
||||
cmd := exec.Command("gpg", args...)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// GpgClearSign clear-signs the file
|
||||
func GpgClearSign(source string, destination string) error {
|
||||
cmd := exec.Command("gpg", "-o", destination, "--yes", "--clearsign", source)
|
||||
// ClearSign clear-signs the file
|
||||
func (g *GpgSigner) ClearSign(source string, destination string) error {
|
||||
args := []string{"-o", destination, "--yes"}
|
||||
if g.keyRef != "" {
|
||||
args = append(args, "-u", g.keyRef)
|
||||
}
|
||||
args = append(args, "--clearsign", source)
|
||||
cmd := exec.Command("gpg", args...)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user