mirror of
https://github.com/awnumar/memguard.git
synced 2026-02-07 10:19:55 +00:00
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
44 lines
757 B
Go
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)
|
|
}
|
|
}
|