aboutsummaryrefslogtreecommitdiff
path: root/gpg
diff options
context:
space:
mode:
Diffstat (limited to 'gpg')
-rw-r--r--gpg/gpg.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/gpg/gpg.go b/gpg/gpg.go
index 4639ae2..1ab71ec 100644
--- a/gpg/gpg.go
+++ b/gpg/gpg.go
@@ -12,10 +12,7 @@ type Signer struct {
Key string
}
-// 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)
-
+func filter(cmd *exec.Cmd, b []byte) ([]byte, error) {
cmd.Stdin = bytes.NewReader(b)
var out bytes.Buffer
cmd.Stdout = &out
@@ -24,6 +21,12 @@ func (s Signer) Sign(b []byte) ([]byte, error) {
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{}
@@ -33,3 +36,24 @@ func (Verifyer) Verify(b []byte) error {
cmd.Stdin = bytes.NewReader(b)
return cmd.Run()
}
+
+type Encrypter struct {
+ Key string
+}
+
+func (e Encrypter) Encrypt(b []byte) ([]byte, error) {
+ cmd := exec.Command("gpg", "--encrypt", "--recipient", e.Key)
+ return filter(cmd, b)
+}
+
+type Decrypter struct{}
+
+func (Decrypter) Decrypt(b []byte) ([]byte, error) {
+ cmd := exec.Command("gpg", "--decrypt")
+ return filter(cmd, b)
+}
+
+type Crypter struct {
+ Encrypter
+ Decrypter
+}