diff options
Diffstat (limited to 'lib/crypto/gpg/gpgbin')
-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 +} |