parseRecipient attempts to parse a string containing an encoded age public key or a public ssh key.
(recipient string)
| 487 | // parseRecipient attempts to parse a string containing an encoded age public |
| 488 | // key or a public ssh key. |
| 489 | func parseRecipient(recipient string) (age.Recipient, error) { |
| 490 | switch { |
| 491 | case strings.HasPrefix(recipient, "age1pq1"): |
| 492 | parsedRecipient, err := age.ParseHybridRecipient(recipient) |
| 493 | if err != nil { |
| 494 | return nil, fmt.Errorf("failed to parse input as Bech32-encoded age public key: %w", err) |
| 495 | } |
| 496 | |
| 497 | return parsedRecipient, nil |
| 498 | case strings.HasPrefix(recipient, "age1") && strings.Count(recipient, "1") > 1: |
| 499 | parsedRecipient, err := plugin.NewRecipient(recipient, pluginTerminalUI) |
| 500 | if err != nil { |
| 501 | return nil, fmt.Errorf("failed to parse input as age key from age plugin: %w", err) |
| 502 | } |
| 503 | return parsedRecipient, nil |
| 504 | case strings.HasPrefix(recipient, "age1"): |
| 505 | parsedRecipient, err := age.ParseX25519Recipient(recipient) |
| 506 | if err != nil { |
| 507 | return nil, fmt.Errorf("failed to parse input as Bech32-encoded age public key: %w", err) |
| 508 | } |
| 509 | |
| 510 | return parsedRecipient, nil |
| 511 | case strings.HasPrefix(recipient, "ssh-"): |
| 512 | parsedRecipient, err := agessh.ParseRecipient(recipient) |
| 513 | if err != nil { |
| 514 | return nil, fmt.Errorf("failed to parse input as age-ssh public key: %w", err) |
| 515 | } |
| 516 | return parsedRecipient, nil |
| 517 | } |
| 518 | |
| 519 | return nil, fmt.Errorf("failed to parse input, unknown recipient type: %q", recipient) |
| 520 | } |
| 521 | |
| 522 | // parseIdentities attempts to parse one or more age identities from the provided reader. |
| 523 | // One identity per line. |
no outgoing calls