From 9f0fbd4ba8675207ca2b68359faefd7309d0cc4d Mon Sep 17 00:00:00 2001 From: Daniel Lublin Date: Wed, 28 Jun 2023 11:06:16 +0200 Subject: [PATCH] plugin: return error var For conveniently going through multiple identities to find which ones we can handle. --- plugin/encode.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/encode.go b/plugin/encode.go index 5000708a..fdae8c05 100644 --- a/plugin/encode.go +++ b/plugin/encode.go @@ -5,12 +5,15 @@ package plugin import ( + "errors" "fmt" "strings" "filippo.io/age/internal/bech32" ) +var ErrNonPluginIdentity = errors.New("not a plugin identity") + // EncodeIdentity encodes a plugin identity string for a plugin with the given // name. If the name is invalid, it returns an empty string. func EncodeIdentity(name string, data []byte) string { @@ -26,7 +29,7 @@ func ParseIdentity(s string) (name string, data []byte, err error) { return "", nil, fmt.Errorf("invalid identity encoding: %v", err) } if !strings.HasPrefix(hrp, "AGE-PLUGIN-") || !strings.HasSuffix(hrp, "-") { - return "", nil, fmt.Errorf("not a plugin identity: %v", err) + return "", nil, ErrNonPluginIdentity } name = strings.TrimSuffix(strings.TrimPrefix(hrp, "AGE-PLUGIN-"), "-") name = strings.ToLower(name)