aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/gpg/gpgbin/sign.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto/gpg/gpgbin/sign.go')
-rw-r--r--lib/crypto/gpg/gpgbin/sign.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/crypto/gpg/gpgbin/sign.go b/lib/crypto/gpg/gpgbin/sign.go
new file mode 100644
index 00000000..35ab7e7f
--- /dev/null
+++ b/lib/crypto/gpg/gpgbin/sign.go
@@ -0,0 +1,27 @@
+package gpgbin
+
+import (
+ "bytes"
+ "io"
+
+ "git.sr.ht/~rjarry/aerc/models"
+)
+
+// Sign creates a detached signature based on the contents of r
+func Sign(r io.Reader, from string) ([]byte, string, error) {
+ args := []string{
+ "--armor",
+ "--detach-sign",
+ "--default-key", from,
+ }
+
+ g := newGpg(r, args)
+ g.cmd.Run()
+
+ outRdr := bytes.NewReader(g.stdout.Bytes())
+ var md models.MessageDetails
+ parse(outRdr, &md)
+ var buf bytes.Buffer
+ io.Copy(&buf, md.Body)
+ return buf.Bytes(), md.Micalg, nil
+}