memguard/memguard_test.go
Neven Sajko 8750c16425 all: redesign errors in memguard and memguard/core
Memcall is not touched yet. Otherwise this replaces sentinel error
values with IsX exported predicate functions. This enables more
effective error handling by the users and leaves much more freedom for
changing the implementation in the future without breaking API.

Updates #111
2019-08-01 17:12:33 +00:00

44 lines
757 B
Go

package memguard
import (
"bytes"
"testing"
"github.com/awnumar/memguard/core"
)
func TestScrambleBytes(t *testing.T) {
buf := make([]byte, 32)
ScrambleBytes(buf)
if bytes.Equal(buf, make([]byte, 32)) {
t.Error("buffer not scrambled")
}
}
func TestWipeBytes(t *testing.T) {
buf := make([]byte, 32)
ScrambleBytes(buf)
WipeBytes(buf)
if !bytes.Equal(buf, make([]byte, 32)) {
t.Error("buffer not wiped")
}
}
func TestPurge(t *testing.T) {
key := NewEnclaveRandom(32)
buf, err := key.Open()
if err != nil {
t.Error(err)
}
Purge()
if buf.IsAlive() {
t.Error("buffer not destroyed")
}
buf, err = key.Open()
if !core.IsDecryptionFailed(err) {
t.Error(buf.Bytes(), err)
}
if buf != nil {
t.Error("buffer not nil:", buf)
}
}