diff --git a/demo/client b/demo/client index 7e019c3..6683776 100755 Binary files a/demo/client and b/demo/client differ diff --git a/demo/client.go b/demo/client.go index 623bb6c..06d3567 100644 --- a/demo/client.go +++ b/demo/client.go @@ -1,7 +1,6 @@ package main import ( - "bufio" "fmt" "net" @@ -17,8 +16,8 @@ func main() { conn := hkex.NewHKExConn(&bareconn) fmt.Printf("conn: %v\n", conn) - fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n") + // fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n") // status, err := bufio.NewReader(conn).ReadString('\n') - _, err = bufio.NewReader(conn).ReadString('\n') + // _, err = bufio.NewReader(conn).ReadString('\n') // ... } diff --git a/herradurakex.go b/herradurakex.go index 5d5ac16..5cf85cd 100644 --- a/herradurakex.go +++ b/herradurakex.go @@ -35,10 +35,22 @@ type HerraduraKEx struct { fa *big.Int } +//// Returns a new HerraduraKEx struct with default intSz,pubSz +//func New() (h *HerraduraKEx) { +// return New(256, 64) +//} + // Returns a new HerraduraKEx struct func New(i int, p int) (h *HerraduraKEx) { h = new(HerraduraKEx) + if i == 0 { + i = 256 + } + if p == 0 { + p = 64 + } + h.intSz = i h.pubSz = p @@ -133,19 +145,31 @@ func (h *HerraduraKEx) String() string { } type HKExConn struct { - c net.Conn + c net.Conn // which also implements io.Reader, io.Writer, ... + h *HerraduraKEx } // Return c coerced into a HKExConn (which implements interface net.Conn) func NewHKExConn(c *net.Conn) (hc *HKExConn) { - fmt.Println("** NewHKExConn wrapping net.Conn **") - return &HKExConn{*c} + //fmt.Println("** NewHKExConn wrapping net.Conn **") + hc = new(HKExConn) + + hc.c = *c + hc.h = New(0,0) + d := big.NewInt(0) + _,err := fmt.Fscanln(hc.c, d) + if err != nil { + // + } + hc.h.PeerD = d + fmt.Printf("** peerD:%s\n", hc.h.PeerD.Text(16)) + return } func (hc HKExConn) Read(b []byte) (n int, err error) { n, err = hc.c.Read(b) if n > 0 { - fmt.Println("** hc.Read() wraps c.Read() **") + //fmt.Println("** hc.Read() wraps c.Read() **") } return } @@ -153,7 +177,7 @@ func (hc HKExConn) Read(b []byte) (n int, err error) { func (hc HKExConn) Write(b []byte) (n int, err error) { n, err = hc.c.Write(b) if n > 0 { - fmt.Printf("** hc.Write('%s') wraps c.Write() **\n", b) + //fmt.Printf("** hc.Write('%s') wraps c.Write() **\n", b) } return }