MCPcopy
hub / github.com/FiloSottile/age / ParseIdentity

Function ParseIdentity

plugin/encode.go:29–43  ·  view source on GitHub ↗

ParseIdentity decodes a plugin identity string. It returns the plugin name in lowercase and the encoded data.

(s string)

Source from the content-addressed store, hash-verified

27// ParseIdentity decodes a plugin identity string. It returns the plugin name
28// in lowercase and the encoded data.
29func ParseIdentity(s string) (name string, data []byte, err error) {
30 hrp, data, err := bech32.Decode(s)
31 if err != nil {
32 return "", nil, fmt.Errorf("invalid identity encoding: %v", err)
33 }
34 if !strings.HasPrefix(hrp, "AGE-PLUGIN-") || !strings.HasSuffix(hrp, "-") {
35 return "", nil, fmt.Errorf("not a plugin identity: %v", err)
36 }
37 name = strings.TrimSuffix(strings.TrimPrefix(hrp, "AGE-PLUGIN-"), "-")
38 name = strings.ToLower(name)
39 if !validPluginName(name) {
40 return "", nil, fmt.Errorf("invalid plugin name: %q", name)
41 }
42 return name, data, nil
43}
44
45// EncodeRecipient encodes a plugin recipient string for a plugin with the given
46// name. If the name is invalid, it returns an empty string.

Callers 3

RecipientV1Method · 0.70
IdentityV1Method · 0.70
NewIdentityFunction · 0.70

Calls 2

DecodeFunction · 0.92
validPluginNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…