blob: cb62f32ce96a743c60439800b6d0325fa8113530 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package gpg
// Package gpg wraps around the gpg command line tool and exposes some of its functionality
import (
"bytes"
"os/exec"
)
// Signer implements objects.Signer using gpg
type Signer struct {
Key string
}
func filter(cmd *exec.Cmd, b []byte) ([]byte, error) {
cmd.Stdin = bytes.NewReader(b)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
return out.Bytes(), err
}
// Sign signs a message b with the key s.Key
func (s Signer) Sign(b []byte) ([]byte, error) {
cmd := exec.Command("gpg", "--clearsign", "-u", s.Key)
return filter(cmd, b)
}
// Verifyer implements objects.Verifyer using gpg
type Verifyer struct{}
// Verify verifies the signed message b
func (Verifyer) Verify(b []byte) error {
cmd := exec.Command("gpg", "--verify")
cmd.Stdin = bytes.NewReader(b)
return cmd.Run()
}
|