mirror of https://gogs.blitter.com/RLabs/xs
Bit of cleanup in hkex.Read(),Write() and server.go read bufsize to 512
This commit is contained in:
parent
c43b13989b
commit
d4c9a1e456
|
@ -44,7 +44,7 @@ func main() {
|
||||||
go func(ch chan []byte, eCh chan error) {
|
go func(ch chan []byte, eCh chan error) {
|
||||||
for {
|
for {
|
||||||
// try to read the data
|
// try to read the data
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 512)
|
||||||
chN, err = c.Read(data)
|
chN, err = c.Read(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// send an error if it's encountered
|
// send an error if it's encountered
|
||||||
|
|
17
hkexnet.go
17
hkexnet.go
|
@ -126,13 +126,14 @@ func (hc Conn) Read(b []byte) (n int, err error) {
|
||||||
if err != nil && err.Error() != "EOF" {
|
if err != nil && err.Error() != "EOF" {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if n > 0 {
|
fmt.Printf(" ctext:%+v\n", b[:n]) // print only used portion
|
||||||
fmt.Printf(" ctext:%+v\n", b[:n])
|
db := bytes.NewBuffer(b[:n])
|
||||||
db := bytes.NewBuffer(b[:n])
|
// The StreamReader acts like a pipe, decrypting
|
||||||
rs := &cipher.StreamReader{S: hc.r, R: db}
|
// whatever is available and forwarding the result
|
||||||
n, err = rs.Read(b)
|
// to the parameter of Read() as a normal io.Reader
|
||||||
fmt.Printf(" ptext:%+v\n", b[:n])
|
rs := &cipher.StreamReader{S: hc.r, R: db}
|
||||||
}
|
n, err = rs.Read(b)
|
||||||
|
fmt.Printf(" ptext:%+v\n", b[:n])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +141,8 @@ func (hc Conn) Write(b []byte) (n int, err error) {
|
||||||
fmt.Printf("[Encrypting...]\n")
|
fmt.Printf("[Encrypting...]\n")
|
||||||
fmt.Printf(" ptext:%+v\n", b)
|
fmt.Printf(" ptext:%+v\n", b)
|
||||||
var wb bytes.Buffer
|
var wb bytes.Buffer
|
||||||
|
// The StreamWriter acts like a pipe, forwarding whatever is
|
||||||
|
// written to it through the cipher, encrypting as it goes
|
||||||
ws := &cipher.StreamWriter{S: hc.w, W: &wb}
|
ws := &cipher.StreamWriter{S: hc.w, W: &wb}
|
||||||
n, err = ws.Write(b)
|
n, err = ws.Write(b)
|
||||||
fmt.Printf(" ctext:%+v\n", wb.Bytes())
|
fmt.Printf(" ctext:%+v\n", wb.Bytes())
|
||||||
|
|
Loading…
Reference in New Issue