diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-05-05 12:53:16 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-05-06 11:02:55 +0200 |
commit | b57fceaad4bfcbd4ca3022e013b73eff72079c0b (patch) | |
tree | 7e68b206ca5b5dd7d1e2a8793360a80963c0c1df /lib/crypto/gpg/gpgbin/keys.go | |
parent | 32a16dcd8dc488c1f360553d9d9f6d121af1b367 (diff) | |
download | aerc-b57fceaad4bfcbd4ca3022e013b73eff72079c0b.tar.gz |
pgp: add attach key command
Add compose command ("attach-key") to attach the public key associated
with the sending account. Public key is attached in ascii armor format,
with the mimetype set according to RFC 3156 ("application/pgp-keys").
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'lib/crypto/gpg/gpgbin/keys.go')
-rw-r--r-- | lib/crypto/gpg/gpgbin/keys.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/crypto/gpg/gpgbin/keys.go b/lib/crypto/gpg/gpgbin/keys.go index 9c8b233f..bef90cf6 100644 --- a/lib/crypto/gpg/gpgbin/keys.go +++ b/lib/crypto/gpg/gpgbin/keys.go @@ -1,6 +1,12 @@ package gpgbin -import "fmt" +import ( + "bytes" + "fmt" + "io" + "os/exec" + "strings" +) // GetPrivateKeyId runs gpg --list-secret-keys s func GetPrivateKeyId(s string) (string, error) { @@ -21,3 +27,18 @@ func GetKeyId(s string) (string, error) { } return id, nil } + +// ExportPublicKey exports the public key identified by k in armor format +func ExportPublicKey(k string) (io.Reader, error) { + cmd := exec.Command("gpg", "--export", "--armor", k) + + var outbuf bytes.Buffer + var stderr strings.Builder + cmd.Stdout = &outbuf + cmd.Stderr = &stderr + cmd.Run() + if strings.Contains(stderr.String(), "gpg") { + return nil, fmt.Errorf("gpg: error exporting key") + } + return &outbuf, nil +} |