File: memguard_test.go

package info (click to toggle)
golang-github-awnumar-memguard 0.22.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 572 kB
  • sloc: makefile: 3
file content (44 lines) | stat: -rw-r--r-- 759 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 err != core.ErrDecryptionFailed {
		t.Error(buf.Bytes(), err)
	}
	if buf != nil {
		t.Error("buffer not nil:", buf)
	}
}