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) {
|
||||
for {
|
||||
// try to read the data
|
||||
data := make([]byte, 8)
|
||||
data := make([]byte, 512)
|
||||
chN, err = c.Read(data)
|
||||
if err != nil {
|
||||
// send an error if it's encountered
|
||||
|
|
|
@ -126,13 +126,14 @@ func (hc Conn) Read(b []byte) (n int, err error) {
|
|||
if err != nil && err.Error() != "EOF" {
|
||||
panic(err)
|
||||
}
|
||||
if n > 0 {
|
||||
fmt.Printf(" ctext:%+v\n", b[:n])
|
||||
fmt.Printf(" ctext:%+v\n", b[:n]) // print only used portion
|
||||
db := bytes.NewBuffer(b[:n])
|
||||
// The StreamReader acts like a pipe, decrypting
|
||||
// whatever is available and forwarding the result
|
||||
// to the parameter of Read() as a normal io.Reader
|
||||
rs := &cipher.StreamReader{S: hc.r, R: db}
|
||||
n, err = rs.Read(b)
|
||||
fmt.Printf(" ptext:%+v\n", b[:n])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -140,6 +141,8 @@ func (hc Conn) Write(b []byte) (n int, err error) {
|
|||
fmt.Printf("[Encrypting...]\n")
|
||||
fmt.Printf(" ptext:%+v\n", b)
|
||||
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}
|
||||
n, err = ws.Write(b)
|
||||
fmt.Printf(" ctext:%+v\n", wb.Bytes())
|
||||
|
|
Loading…
Reference in New Issue