mirror of
https://github.com/FiloSottile/age.git
synced 2026-03-11 08:55:41 +00:00
plugin: return error var
For conveniently going through multiple identities to find which ones we can handle.
This commit is contained in:
parent
3d91014ea0
commit
839abf2df6
1 changed files with 4 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
@ -29,7 +32,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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue