[client:client] implemented 'Receive(io.Reader)' for reading 'errorCode' then validating migration or rescuing key if failure
This commit is contained in:
parent
8b6d5a12cd
commit
87a884abdc
|
@ -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> Error
|
||||
*
|
||||
---------------------------------------------------------*/
|
||||
func (c *T) Receive(r io.Reader) error { return nil }
|
||||
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
|
||||
|
||||
}
|
Loading…
Reference in New Issue