aboutsummaryrefslogtreecommitdiff
path: root/gpg
diff options
context:
space:
mode:
Diffstat (limited to 'gpg')
-rw-r--r--gpg/gpg.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/gpg/gpg.go b/gpg/gpg.go
new file mode 100644
index 0000000..4639ae2
--- /dev/null
+++ b/gpg/gpg.go
@@ -0,0 +1,35 @@
+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
+}
+
+// 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)
+
+ cmd.Stdin = bytes.NewReader(b)
+ var out bytes.Buffer
+ cmd.Stdout = &out
+
+ err := cmd.Run()
+ return out.Bytes(), err
+}
+
+// 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()
+}