From 61f99cf9407a61e12c7310a35b3826d15681d5ea Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 24 Apr 2018 23:10:26 +0200 Subject: [PATCH] [server] added 'synchronisationKey([]byte)' to apply a new synchronisation key with length check --- src/git.xdrm.io/schastsp/server/server.go | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/git.xdrm.io/schastsp/server/server.go b/src/git.xdrm.io/schastsp/server/server.go index 7e79c17..d0aa236 100644 --- a/src/git.xdrm.io/schastsp/server/server.go +++ b/src/git.xdrm.io/schastsp/server/server.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "git.xdrm.io/schastsp/pkg/scha" "io" "os" @@ -135,4 +136,30 @@ func (s *T) HandleRequest(req io.Reader, res io.Writer) error { if written != len(y1) { return errors.New("Cannot write y2") } return nil +} + + + +/* (4) Apply a synchronisation key +* +* @syncKey<[]byte> Synchronisation key from client +* +* @return err +* +---------------------------------------------------------*/ +func (s *T) SynchronisationKey(syncKey []byte) error { + + /* (1) Check size */ + if uint16(len(syncKey)) != scha.HSIZE { + return fmt.Errorf("Invalid synchronisation key size (%d), expected %d bytes", len(syncKey), scha.HSIZE) + } + + /* (2) Copy synchronisation key */ + copy(s.hash, syncKey) + + /* (3) Store new config */ + s.store() + + return nil + } \ No newline at end of file