MCPcopy
hub / github.com/FiloSottile/age / RecipientV1

Method RecipientV1

plugin/plugin.go:182–350  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

180//
181// Most plugins should call [Plugin.Main] instead of this method.
182func (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))
192ReadLoop:
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)

Callers 1

MainMethod · 0.95

Calls 15

fatalfMethod · 0.95
recipientErrorMethod · 0.95
identityErrorMethod · 0.95
NewStanzaReaderFunction · 0.92
expectStanzaWithNoBodyFunction · 0.85
expectStanzaWithBodyFunction · 0.85
checkLabelsFunction · 0.85
writeGreaseFunction · 0.85
expectUnsupportedFunction · 0.85
writeStanzaFunction · 0.85
expectOkFunction · 0.85
ReadStanzaMethod · 0.80

Tested by

no test coverage detected