[#290] util: Implement salting writer

Implement wrapper over io.Writer that applies binary salt to written data.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-11 16:47:35 +03:00 committed by Alex Vanin
parent 3bbd0bc95c
commit ba03f46316
2 changed files with 76 additions and 2 deletions

34
pkg/util/salt_test.go Normal file
View file

@ -0,0 +1,34 @@
package util_test
import (
"bytes"
"crypto/rand"
"testing"
"github.com/nspcc-dev/neofs-node/pkg/util"
"github.com/stretchr/testify/require"
)
func randData(sz int) []byte {
data := make([]byte, sz)
_, _ = rand.Read(data)
return data
}
func TestSaltWriter_Write(t *testing.T) {
salt := randData(4)
data := randData(15)
buf := bytes.NewBuffer(nil)
w := util.NewSaltingWriter(buf, salt)
_, err := w.Write(data)
require.NoError(t, err)
require.Equal(t,
buf.Bytes(),
util.SaltXOR(data, salt),
)
}