diff --git a/src/git.xdrm.io/schastsp/client/client.go b/src/git.xdrm.io/schastsp/client/client.go index b1a88d2..94ba94a 100644 --- a/src/git.xdrm.io/schastsp/client/client.go +++ b/src/git.xdrm.io/schastsp/client/client.go @@ -1,6 +1,9 @@ package client; import ( + "fmt" + "errors" + "git.xdrm.io/schastsp/lib/scha" "io" "git.xdrm.io/schastsp/context" "git.xdrm.io/schastsp/client/keyset" @@ -85,4 +88,50 @@ func (c *T) Send(w io.Writer) error { * @return err Error * ---------------------------------------------------------*/ -func (c *T) Receive(r io.Reader) error { return nil } \ No newline at end of file +func (c *T) Receive(r io.Reader) error { + + /* (1) Read error code + ---------------------------------------------------------*/ + errCode := make([]byte, 1) + read, err := r.Read(errCode) + if err != nil { return err } + if uint16(read) != 1 { return errors.New("Cannot read enough bytes") } + + + /* (2) Manage success + ---------------------------------------------------------*/ + if errCode[0] == 0 { + + /* (1) If pending migration -> migrate */ + if c.key.MigrationCode() == 2 { + c.key.MigrationCode(3) + if DEBUG { fmt.Printf("*** VALIDATED MIGRATION\n") } + } + + /* (2) No error anyway */ + return nil; + + } + + + /* (3) Manage rescue + ---------------------------------------------------------*/ + /* (1) Read y1 */ + y1 := make([]byte, scha.HSIZE); + read, err = r.Read(y1) + if err != nil { return err } + if uint16(read) != scha.HSIZE { return errors.New("Cannot read enough bytes") } + + /* (2) Read y2 */ + y2 := make([]byte, scha.HSIZE); + read, err = r.Read(y2) + if err != nil { return err } + if uint16(read) != scha.HSIZE { return errors.New("Cannot read enough bytes") } + + /* (3) Manage rescue mode */ + err = c.rescue(y1, y2); + + /* (4) Dispatch err */ + return err + +} \ No newline at end of file