aboutsummaryrefslogtreecommitdiff
path: root/gpg
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2017-09-14 07:42:50 +0200
committerLaria Carolin Chabowski <laria@laria.me>2017-09-26 21:35:41 +0200
commitb2742dc28d1ff9001cd784455bbdf9cf29539c30 (patch)
tree2cac9dff572edbfc05588c33cce76a3dbb406d15 /gpg
parent9ddda1c317dbeaab1380e46ebf48eba9566a90e2 (diff)
downloadpetrific-b2742dc28d1ff9001cd784455bbdf9cf29539c30.tar.gz
petrific-b2742dc28d1ff9001cd784455bbdf9cf29539c30.tar.bz2
petrific-b2742dc28d1ff9001cd784455bbdf9cf29539c30.zip
Implement remaining subcommands
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()
+}