(stanzas []*age.Stanza)
| 222 | } |
| 223 | |
| 224 | func (i *Identity) Unwrap(stanzas []*age.Stanza) (fileKey []byte, err error) { |
| 225 | defer func() { |
| 226 | if err != nil { |
| 227 | err = fmt.Errorf("%s plugin: %w", i.name, err) |
| 228 | } |
| 229 | }() |
| 230 | |
| 231 | conn, err := openClientConnection(i.name, "identity-v1") |
| 232 | if err != nil { |
| 233 | return nil, fmt.Errorf("couldn't start plugin: %w", err) |
| 234 | } |
| 235 | defer conn.Close() |
| 236 | |
| 237 | // Phase 1: client sends the plugin the identity string and the stanzas |
| 238 | if err := writeStanza(conn, "add-identity", i.encoding); err != nil { |
| 239 | return nil, err |
| 240 | } |
| 241 | if _, err := writeGrease(conn); err != nil { |
| 242 | return nil, err |
| 243 | } |
| 244 | for _, rs := range stanzas { |
| 245 | s := &format.Stanza{ |
| 246 | Type: "recipient-stanza", |
| 247 | Args: append([]string{"0", rs.Type}, rs.Args...), |
| 248 | Body: rs.Body, |
| 249 | } |
| 250 | if err := s.Marshal(conn); err != nil { |
| 251 | return nil, err |
| 252 | } |
| 253 | } |
| 254 | if err := writeStanza(conn, "done"); err != nil { |
| 255 | return nil, err |
| 256 | } |
| 257 | |
| 258 | // Phase 2: plugin responds with various commands and a file key |
| 259 | sr := format.NewStanzaReader(bufio.NewReader(conn)) |
| 260 | ReadLoop: |
| 261 | for { |
| 262 | s, err := i.ui.readStanza(i.name, sr) |
| 263 | if err != nil { |
| 264 | return nil, err |
| 265 | } |
| 266 | |
| 267 | switch s.Type { |
| 268 | case "file-key": |
| 269 | if len(s.Args) != 1 { |
| 270 | return nil, fmt.Errorf("malformed file-key stanza: unexpected arguments count") |
| 271 | } |
| 272 | n, err := strconv.Atoi(s.Args[0]) |
| 273 | if err != nil { |
| 274 | return nil, fmt.Errorf("malformed file-key stanza: invalid index") |
| 275 | } |
| 276 | // We only send a single file key, so the index must be 0. |
| 277 | if n != 0 { |
| 278 | return nil, fmt.Errorf("malformed file-key stanza: unexpected index") |
| 279 | } |
| 280 | if fileKey != nil { |
| 281 | return nil, fmt.Errorf("received duplicated file-key stanza") |
nothing calls this directly
no test coverage detected