From 70448dda08e6f07e837ff9c8d166dc29d15341cd Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Fri, 4 May 2018 23:31:06 -0700 Subject: [PATCH] No need for custom hkexsh.Copy() --- hkexnet.go | 39 --------------------------------------- hkexsh/hkexsh.go | 2 +- hkexshd/hkexshd.go | 5 ++--- 3 files changed, 3 insertions(+), 43 deletions(-) diff --git a/hkexnet.go b/hkexnet.go index 05ce922..cb3f4c2 100644 --- a/hkexnet.go +++ b/hkexnet.go @@ -530,42 +530,3 @@ func (c *Conn) chaffHelper(szMax int) { } }() } - -// hkexsh.Copy() is a modified version of io.Copy() -func Copy(dst io.Writer, src io.Reader) (written int64, err error) { - // If the reader has a WriteTo method, use it to do the copy. - // Avoids an allocation and a copy. - if wt, ok := src.(io.WriterTo); ok { - return wt.WriteTo(dst) - } - // Similarly, if the writer has a ReadFrom method, use it to do the copy. - if rt, ok := dst.(io.ReaderFrom); ok { - return rt.ReadFrom(src) - } - - buf := make([]byte, 32*1024) - for { - nr, er := src.Read(buf) - if nr > 0 { - nw, ew := dst.Write(buf[0:nr]) - if nw > 0 { - written += int64(nw) - } - if ew != nil { - err = ew - break - } - if nr != nw { - err = io.ErrShortWrite - break - } - } - if er != nil { - if er != io.EOF { - err = er - } - break - } - } - return written, err -} diff --git a/hkexsh/hkexsh.go b/hkexsh/hkexsh.go index 76a96c7..b0644ac 100644 --- a/hkexsh/hkexsh.go +++ b/hkexsh/hkexsh.go @@ -230,7 +230,7 @@ func main() { //!_, outerr := io.Copy(conn, os.Stdin) conn.Chaff(true, 100, 500, 32) // enable client->server chaffing _, outerr := func(conn *hkexsh.Conn, r io.Reader) (w int64, e error) { - return hkexsh.Copy(conn, r) + return io.Copy(conn, r) }(conn, os.Stdin) if outerr != nil { diff --git a/hkexshd/hkexshd.go b/hkexshd/hkexshd.go index e33180f..8882510 100644 --- a/hkexshd/hkexshd.go +++ b/hkexshd/hkexshd.go @@ -131,7 +131,7 @@ func runShellAs(who string, cmd string, interactive bool, conn hkexsh.Conn) (err // Copy stdin to the pty.. (bgnd goroutine) go func() { - _, _ = hkexsh.Copy(ptmx, conn) + _, _ = io.Copy(ptmx, conn) }() // ..and the pty to stdout. @@ -140,8 +140,7 @@ func runShellAs(who string, cmd string, interactive bool, conn hkexsh.Conn) (err // --knowledge of another thread which would do chaffing. // --Modify pty somehow to slave the command through hkexsh.Copy() ? conn.Chaff(true, 100, 500, 32) - _, _ = hkexsh.Copy(conn, ptmx) - //_, _ = io.Copy(conn, ptmx) + _, _ = io.Copy(conn, ptmx) //err = c.Run() // returns when c finishes.