util: password: Add a new helper util function for passwords

Also fix some doc issues from an earlier copy paste.
This commit is contained in:
James Shubin
2024-03-22 00:12:57 -04:00
parent 946468dc99
commit b8a3c39984

View File

@@ -66,12 +66,20 @@ func ReadPassword() ([]byte, error) {
// ReadPasswordCtx reads a password from stdin and returns the result. It hides // ReadPasswordCtx reads a password from stdin and returns the result. It hides
// the display of the password typed. It cancels reading when the context // the display of the password typed. It cancels reading when the context
// closes. For more options try ReadPasswordCtxFdPrompt instead. If interrupted // closes. For more options try ReadPasswordCtxFdPrompt instead. If interrupted
// by an uncaught signal during read, then this can bork your terminal. It's // by an uncaught signal during read, then this can bork your terminal.
// best to use a version with a context instead.
func ReadPasswordCtx(ctx context.Context) ([]byte, error) { func ReadPasswordCtx(ctx context.Context) ([]byte, error) {
return ReadPasswordCtxFdPrompt(ctx, int(os.Stdin.Fd()), StdPrompt) return ReadPasswordCtxFdPrompt(ctx, int(os.Stdin.Fd()), StdPrompt)
} }
// ReadPasswordCtxPrompt reads a password stdin and returns the result. It hides
// the display of the password typed. It cancels reading when the context
// closes. If specified, it will prompt the user with the prompt message. If
// interrupted by an uncaught signal during read, then this can bork your
// terminal.
func ReadPasswordCtxPrompt(ctx context.Context, prompt string) ([]byte, error) {
return ReadPasswordCtxFdPrompt(ctx, int(os.Stdin.Fd()), prompt)
}
// ReadPasswordCtxFdPrompt reads a password from the file descriptor and returns // ReadPasswordCtxFdPrompt reads a password from the file descriptor and returns
// the result. It hides the display of the password typed. It cancels reading // the result. It hides the display of the password typed. It cancels reading
// when the context closes. If specified, it will prompt the user with the // when the context closes. If specified, it will prompt the user with the