From 5c1f0b383990e026f796285c5ce3803da528dc20 Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Sat, 30 Sep 2023 23:05:45 +0800 Subject: [PATCH] gpgme: add gpgme_get_dirinfo --- gpgme.go | 20 +++++++++++++++++--- gpgme_test.go | 12 ++++++++++++ unset_agent_info.go | 1 + 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/gpgme.go b/gpgme.go index d253387c7c..15af69c865 100644 --- a/gpgme.go +++ b/gpgme.go @@ -7,6 +7,7 @@ package gpgme // #include // #include "go_gpgme.h" import "C" + import ( "fmt" "io" @@ -235,6 +236,17 @@ func SetEngineInfo(proto Protocol, fileName, homeDir string) error { return handleError(C.gpgme_set_engine_info(C.gpgme_protocol_t(proto), cfn, chome)) } +func GetDirInfo(what string) string { + cwhat := C.CString(what) + defer C.free(unsafe.Pointer(cwhat)) + + cdir := C.gpgme_get_dirinfo(cwhat) + if cdir == nil { + return "" + } + return C.GoString(cdir) +} + func FindKeys(pattern string, secretOnly bool) ([]*Key, error) { var keys []*Key ctx, err := New() @@ -567,9 +579,11 @@ func (c *Context) Sign(signers []*Key, plain, sig *Data, mode SigMode) error { return err } -type AssuanDataCallback func(data []byte) error -type AssuanInquireCallback func(name, args string) error -type AssuanStatusCallback func(status, args string) error +type ( + AssuanDataCallback func(data []byte) error + AssuanInquireCallback func(name, args string) error + AssuanStatusCallback func(status, args string) error +) // AssuanSend sends a raw Assuan command to gpg-agent func (c *Context) AssuanSend( diff --git a/gpgme_test.go b/gpgme_test.go index aab84deba9..49ea5bdf3f 100644 --- a/gpgme_test.go +++ b/gpgme_test.go @@ -105,6 +105,18 @@ func TestEngineInfo(t *testing.T) { checkError(t, SetEngineInfo(testProto, "", testHomeDir)) } +func TestGetDirInfo(t *testing.T) { + info := GetDirInfo("fail") + if info != "" { + t.Errorf("expected no info, got: %q", info) + } + + info = GetDirInfo("homedir") + if info == "" { + t.Error("expected dir info, got nothing") + } +} + func ctxWithCallback(t *testing.T) *Context { ensureVersion(t, "1.", "can only set password callback for GPG v1.x") diff --git a/unset_agent_info.go b/unset_agent_info.go index 986aca59f6..8add8ec877 100644 --- a/unset_agent_info.go +++ b/unset_agent_info.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package gpgme