MCPcopy Index your code
hub / github.com/getsops/sops / parseRecipient

Function parseRecipient

age/keysource.go:489–520  ·  view source on GitHub ↗

parseRecipient attempts to parse a string containing an encoded age public key or a public ssh key.

(recipient string)

Source from the content-addressed store, hash-verified

487// parseRecipient attempts to parse a string containing an encoded age public
488// key or a public ssh key.
489func 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.

Callers 3

MasterKeyFromRecipientFunction · 0.85
EncryptMethod · 0.85
TestMasterKey_EncryptFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestMasterKey_EncryptFunction · 0.68