Fixes for build constraints, MakeRaw()/ReadPassword() etc. fd arg type

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2020-04-25 18:42:18 -07:00
parent 47a3c6f1b8
commit 1d30b8582d
4 changed files with 15 additions and 12 deletions

2
go.sum
View File

@ -10,6 +10,8 @@ blitter.com/go/goutmp v1.0.1 h1:jBqtp6pDwSbF4QEC3DjNfyaS8Nv5dFCOyaTfSbbb7TU=
blitter.com/go/goutmp v1.0.1/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk= blitter.com/go/goutmp v1.0.1/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk=
blitter.com/go/goutmp v1.0.2 h1:oCc/dt9TlTOP2kvmX1Y7J/wSQUhywjcyF101jXuLxZ8= blitter.com/go/goutmp v1.0.2 h1:oCc/dt9TlTOP2kvmX1Y7J/wSQUhywjcyF101jXuLxZ8=
blitter.com/go/goutmp v1.0.2/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk= blitter.com/go/goutmp v1.0.2/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk=
blitter.com/go/goutmp v1.0.3 h1:4VPU9COXG36W5454pcV65FieVaaw64mdhvjuTVOuWTM=
blitter.com/go/goutmp v1.0.3/go.mod h1:gtlbjC8xGzMk/Cf0BpnVltSa3awOqJ+B5WAxVptTMxk=
blitter.com/go/herradurakex v1.0.0 h1:6XaxY+JLT1HUWPF0gYJnjX3pVjrw4YhYZEzZ1U0wkyc= blitter.com/go/herradurakex v1.0.0 h1:6XaxY+JLT1HUWPF0gYJnjX3pVjrw4YhYZEzZ1U0wkyc=
blitter.com/go/herradurakex v1.0.0/go.mod h1:m3+vYZX+2dDjdo+n/HDnXEYJX9pwmNeQLgAfJM8mtxw= blitter.com/go/herradurakex v1.0.0/go.mod h1:m3+vYZX+2dDjdo+n/HDnXEYJX9pwmNeQLgAfJM8mtxw=
blitter.com/go/kyber v0.0.0-20200130200857-6f2021cb88d9 h1:D45AnrNphtvczBXRp5JQicZRTgaK/Is5bgPDDvRKhTc= blitter.com/go/kyber v0.0.0-20200130200857-6f2021cb88d9 h1:D45AnrNphtvczBXRp5JQicZRTgaK/Is5bgPDDvRKhTc=

View File

@ -30,8 +30,8 @@ type State struct {
// MakeRaw put the terminal connected to the given file descriptor into raw // MakeRaw put the terminal connected to the given file descriptor into raw
// mode and returns the previous state of the terminal so that it can be // mode and returns the previous state of the terminal so that it can be
// restored. // restored.
func MakeRaw(fd int) (*State, error) { func MakeRaw(fd uintptr) (*State, error) {
termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) termios, err := unix.IoctlGetTermios(int(fd), ioctlReadTermios)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -47,7 +47,7 @@ func MakeRaw(fd int) (*State, error) {
termios.Cflag |= unix.CS8 termios.Cflag |= unix.CS8
termios.Cc[unix.VMIN] = 1 termios.Cc[unix.VMIN] = 1
termios.Cc[unix.VTIME] = 0 termios.Cc[unix.VTIME] = 0
if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, termios); err != nil { if err := unix.IoctlSetTermios(int(fd), ioctlWriteTermios, termios); err != nil {
return nil, err return nil, err
} }
@ -56,8 +56,8 @@ func MakeRaw(fd int) (*State, error) {
// GetState returns the current state of a terminal which may be useful to // GetState returns the current state of a terminal which may be useful to
// restore the terminal after a signal. // restore the terminal after a signal.
func GetState(fd int) (*State, error) { func GetState(fd uintptr) (*State, error) {
termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) termios, err := unix.IoctlGetTermios(int(fd), ioctlReadTermios)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -67,9 +67,9 @@ func GetState(fd int) (*State, error) {
// Restore restores the terminal connected to the given file descriptor to a // Restore restores the terminal connected to the given file descriptor to a
// previous state. // previous state.
func Restore(fd int, state *State) error { func Restore(fd uintptr, state *State) error {
if state != nil { if state != nil {
return unix.IoctlSetTermios(fd, ioctlWriteTermios, &state.termios) return unix.IoctlSetTermios(int(fd), ioctlWriteTermios, &state.termios)
} else { } else {
return errors.New("nil State") return errors.New("nil State")
} }
@ -78,8 +78,8 @@ func Restore(fd int, state *State) error {
// ReadPassword reads a line of input from a terminal without local echo. This // ReadPassword reads a line of input from a terminal without local echo. This
// is commonly used for inputting passwords and other sensitive data. The slice // is commonly used for inputting passwords and other sensitive data. The slice
// returned does not include the \n. // returned does not include the \n.
func ReadPassword(fd int) ([]byte, error) { func ReadPassword(fd uintptr) ([]byte, error) {
termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios) termios, err := unix.IoctlGetTermios(int(fd), ioctlReadTermios)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -88,12 +88,12 @@ func ReadPassword(fd int) ([]byte, error) {
newState.Lflag &^= unix.ECHO newState.Lflag &^= unix.ECHO
newState.Lflag |= unix.ICANON | unix.ISIG newState.Lflag |= unix.ICANON | unix.ISIG
newState.Iflag |= unix.ICRNL newState.Iflag |= unix.ICRNL
if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newState); err != nil { if err := unix.IoctlSetTermios(int(fd), ioctlWriteTermios, &newState); err != nil {
return nil, err return nil, err
} }
defer func() { defer func() {
_ = unix.IoctlSetTermios(fd, ioctlWriteTermios, termios) // nolint: gosec _ = unix.IoctlSetTermios(int(fd), ioctlWriteTermios, termios) // nolint: gosec
}() }()
return readPasswordLine(passwordReader(fd)) return readPasswordLine(passwordReader(fd))

View File

@ -1,5 +1,5 @@
// +build windows // +build windows
//
// Note the terminal manipulation functions herein are mostly stubs. They // Note the terminal manipulation functions herein are mostly stubs. They
// don't really do anything and the xs demo client depends on a wrapper // don't really do anything and the xs demo client depends on a wrapper
// script using the 'stty' tool to actually set the proper mode for // script using the 'stty' tool to actually set the proper mode for

View File

@ -1,4 +1,5 @@
// +build linux freebsd // +build linux freebsd
package main package main
import ( import (