From 1c4ccb28ac25d77a28e1cf53872b1d777bf4c2bb Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Thu, 13 Mar 2025 17:38:43 +0100 Subject: [PATCH] Client update to gopenpgp v3 --- api/client.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/api/client.go b/api/client.go index 001fce3..e51ee08 100644 --- a/api/client.go +++ b/api/client.go @@ -6,12 +6,11 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "path" - "github.com/ProtonMail/gopenpgp/v2/crypto" + "github.com/ProtonMail/gopenpgp/v3/crypto" "github.com/google/go-querystring/query" ) @@ -39,6 +38,9 @@ type Client struct { // You need to Return the Cookie that Passbolt expects to verify you MFA, usually it is called passbolt_mfa MFACallback func(ctx context.Context, c *Client, res *APIResponse) (http.Cookie, error) + // gopengpg Handler, allow for custom settings in the future + pgp *crypto.PGPHandle + // Enable Debug Logging Debug bool } @@ -67,6 +69,8 @@ func NewClient(httpClient *http.Client, UserAgent, BaseURL, UserPrivateKey, User return nil, fmt.Errorf("Parsing Base URL: %w", err) } + pgp := crypto.PGP() + // Verify that the Given Privatekey and Password are valid and work Together if we were provieded one if UserPrivateKey != "" { privateKeyObj, err := crypto.NewKeyFromArmored(UserPrivateKey) @@ -93,6 +97,7 @@ func NewClient(httpClient *http.Client, UserAgent, BaseURL, UserPrivateKey, User userAgent: UserAgent, userPassword: []byte(UserPassword), userPrivateKey: UserPrivateKey, + pgp: pgp, } return c, err } @@ -150,7 +155,7 @@ func (c *Client) do(ctx context.Context, req *http.Request, v *APIResponse) (*ht resp.Body.Close() }() - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { return resp, fmt.Errorf("Error Reading Resopnse Body: %w", err) } @@ -231,3 +236,8 @@ func (c *Client) setMetadataTypeSettings(ctx context.Context) error { } return nil } + +// GetPGPHandle Gets the Gopgenpgp Handler +func (c *Client) GetPGPHandle() *crypto.PGPHandle { + return c.pgp +}