Skip to content

Commit

Permalink
plugin: return error var
Browse files Browse the repository at this point in the history
For conveniently going through multiple identities to find which ones we
can handle.
  • Loading branch information
quite committed Aug 9, 2023
1 parent 9305563 commit 9f0fbd4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugin/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 9f0fbd4

Please sign in to comment.