Skip to content

Commit 9f0fbd4

Browse files
committed
plugin: return error var
For conveniently going through multiple identities to find which ones we can handle.
1 parent 9305563 commit 9f0fbd4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

plugin/encode.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
package plugin
66

77
import (
8+
"errors"
89
"fmt"
910
"strings"
1011

1112
"filippo.io/age/internal/bech32"
1213
)
1314

15+
var ErrNonPluginIdentity = errors.New("not a plugin identity")
16+
1417
// EncodeIdentity encodes a plugin identity string for a plugin with the given
1518
// name. If the name is invalid, it returns an empty string.
1619
func EncodeIdentity(name string, data []byte) string {
@@ -26,7 +29,7 @@ func ParseIdentity(s string) (name string, data []byte, err error) {
2629
return "", nil, fmt.Errorf("invalid identity encoding: %v", err)
2730
}
2831
if !strings.HasPrefix(hrp, "AGE-PLUGIN-") || !strings.HasSuffix(hrp, "-") {
29-
return "", nil, fmt.Errorf("not a plugin identity: %v", err)
32+
return "", nil, ErrNonPluginIdentity
3033
}
3134
name = strings.TrimSuffix(strings.TrimPrefix(hrp, "AGE-PLUGIN-"), "-")
3235
name = strings.ToLower(name)

0 commit comments

Comments
 (0)