frostfs-node/pkg/util/salt_test.go
Leonard Lyubich ba03f46316 [#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>
2021-01-11 18:40:59 +03:00

34 lines
521 B
Go

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),
)
}