ParseIdentity decodes a plugin identity string. It returns the plugin name in lowercase and the encoded data.
(s string)
| 27 | // ParseIdentity decodes a plugin identity string. It returns the plugin name |
| 28 | // in lowercase and the encoded data. |
| 29 | func 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. |
no test coverage detected
searching dependent graphs…