ParseRecipient decodes a plugin recipient string. It returns the plugin name in lowercase and the encoded data.
(s string)
| 55 | // ParseRecipient decodes a plugin recipient string. It returns the plugin name |
| 56 | // in lowercase and the encoded data. |
| 57 | func ParseRecipient(s string) (name string, data []byte, err error) { |
| 58 | hrp, data, err := bech32.Decode(s) |
| 59 | if err != nil { |
| 60 | return "", nil, fmt.Errorf("invalid recipient encoding: %v", err) |
| 61 | } |
| 62 | if !strings.HasPrefix(hrp, "age1") { |
| 63 | return "", nil, fmt.Errorf("not a plugin recipient: %v", err) |
| 64 | } |
| 65 | name = strings.TrimPrefix(hrp, "age1") |
| 66 | if !validPluginName(name) { |
| 67 | return "", nil, fmt.Errorf("invalid plugin name: %q", name) |
| 68 | } |
| 69 | return name, data, nil |
| 70 | } |
| 71 | |
| 72 | func validPluginName(name string) bool { |
| 73 | if name == "" { |
no test coverage detected
searching dependent graphs…