[server] added 'synchronisationKey([]byte)' to apply a new synchronisation key with length check

This commit is contained in:
xdrm-brackets 2018-04-24 23:10:26 +02:00
parent 7d38485edb
commit 61f99cf940
1 changed files with 27 additions and 0 deletions

View File

@ -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<error>
*
---------------------------------------------------------*/
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
}