mirror of
https://github.com/rwinkhart/go-boilerplate.git
synced 2026-08-27 20:36:29 -04:00
Make WriteToStdin input zeroization optional
This commit is contained in:
+3
-1
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// WriteToStdin is a utility function that writes a byte slice to a command's stdin.
|
// WriteToStdin is a utility function that writes a byte slice to a command's stdin.
|
||||||
func WriteToStdinAndZeroizeInput(cmd *exec.Cmd, input []byte) error {
|
func WriteToStdin(cmd *exec.Cmd, input []byte, zeroizeInput bool) error {
|
||||||
stdin, err := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unable to access stdin for system command: " + err.Error())
|
return errors.New("unable to access stdin for system command: " + err.Error())
|
||||||
@@ -21,7 +21,9 @@ func WriteToStdinAndZeroizeInput(cmd *exec.Cmd, input []byte) error {
|
|||||||
_ = stdin.Close() // error ignored; if stdin could be accessed, it can probably be closed
|
_ = stdin.Close() // error ignored; if stdin could be accessed, it can probably be closed
|
||||||
}(stdin)
|
}(stdin)
|
||||||
_, _ = stdin.Write(input)
|
_, _ = stdin.Write(input)
|
||||||
|
if zeroizeInput {
|
||||||
security.ZeroizeBytes(input)
|
security.ZeroizeBytes(input)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user