gpgExec runs the provided args with the gpgBinary, while restricting it to homeDir when provided. Stdout and stderr can be read from the returned buffers. When the command fails, an error is returned.
(ctx context.Context, homeDir string, args []string, stdin io.Reader)
| 623 | // homeDir when provided. Stdout and stderr can be read from the returned |
| 624 | // buffers. When the command fails, an error is returned. |
| 625 | func gpgExec(ctx context.Context, homeDir string, args []string, stdin io.Reader) (stdout bytes.Buffer, stderr bytes.Buffer, err error) { |
| 626 | if homeDir != "" { |
| 627 | args = append([]string{"--homedir", homeDir}, args...) |
| 628 | } |
| 629 | |
| 630 | cmd := exec.CommandContext(ctx, gpgBinary(), args...) |
| 631 | cmd.Stdin = stdin |
| 632 | cmd.Stdout = &stdout |
| 633 | cmd.Stderr = &stderr |
| 634 | err = cmd.Run() |
| 635 | return |
| 636 | } |
| 637 | |
| 638 | // gpgBinary returns the GnuPG binary which must be used. |
| 639 | // It allows for runtime modifications by setting the replacement binary |