RecipientV1 implements the recipient-v1 state machine. It returns an exit code to pass to os.Exit. Most plugins should call [Plugin.Main] instead of this method.
()
| 180 | // |
| 181 | // Most plugins should call [Plugin.Main] instead of this method. |
| 182 | func (p *Plugin) RecipientV1() int { |
| 183 | if p.recipient == nil && p.idAsRecipient == nil { |
| 184 | return p.fatalf("recipient-v1 not supported") |
| 185 | } |
| 186 | |
| 187 | var recipientStrings, identityStrings []string |
| 188 | var fileKeys [][]byte |
| 189 | var supportsLabels bool |
| 190 | |
| 191 | p.sr = format.NewStanzaReader(bufio.NewReader(p.stdin)) |
| 192 | ReadLoop: |
| 193 | for { |
| 194 | s, err := p.sr.ReadStanza() |
| 195 | if err != nil { |
| 196 | return p.fatalf("failed to read stanza: %v", err) |
| 197 | } |
| 198 | |
| 199 | switch s.Type { |
| 200 | case "add-recipient": |
| 201 | if err := expectStanzaWithNoBody(s, 1); err != nil { |
| 202 | return p.fatalf("%v", err) |
| 203 | } |
| 204 | recipientStrings = append(recipientStrings, s.Args[0]) |
| 205 | case "add-identity": |
| 206 | if err := expectStanzaWithNoBody(s, 1); err != nil { |
| 207 | return p.fatalf("%v", err) |
| 208 | } |
| 209 | identityStrings = append(identityStrings, s.Args[0]) |
| 210 | case "extension-labels": |
| 211 | if err := expectStanzaWithNoBody(s, 0); err != nil { |
| 212 | return p.fatalf("%v", err) |
| 213 | } |
| 214 | supportsLabels = true |
| 215 | case "wrap-file-key": |
| 216 | if err := expectStanzaWithBody(s, 0); err != nil { |
| 217 | return p.fatalf("%v", err) |
| 218 | } |
| 219 | fileKeys = append(fileKeys, s.Body) |
| 220 | case "done": |
| 221 | if err := expectStanzaWithNoBody(s, 0); err != nil { |
| 222 | return p.fatalf("%v", err) |
| 223 | } |
| 224 | break ReadLoop |
| 225 | default: |
| 226 | // Unsupported stanzas in uni-directional phases are ignored. |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | if len(recipientStrings)+len(identityStrings) == 0 { |
| 231 | return p.fatalf("no recipients or identities provided") |
| 232 | } |
| 233 | if len(fileKeys) == 0 { |
| 234 | return p.fatalf("no file keys provided") |
| 235 | } |
| 236 | |
| 237 | var recipients, identities []age.Recipient |
| 238 | for i, s := range recipientStrings { |
| 239 | name, data, err := ParseRecipient(s) |
no test coverage detected