Skip to content
quarry Artifact [ac97ca7816]
Login

Artifact [ac97ca7816]

Artifact ac97ca7816b02e92e4c6dbd6a38bbf18aff6db187ba8e20bd8ac9ed9139c3703:


package oltp

import (
	"bytes"
	"testing"
)

// A derived key is stable for its purpose across opens of the same data
// directory, differs between purposes, and is not the sealing key.
func TestDerivedKeyIsStablePerPurpose(t *testing.T) {
	d := testDB(t)
	a, err := d.DerivedKey("one")
	if err != nil {
		t.Fatalf("FAIL: %v", err)
	}
	b, _ := d.DerivedKey("one")
	c, _ := d.DerivedKey("two")
	if !bytes.Equal(a, b) || len(a) != 32 {
		t.Errorf("FAIL: not stable, or not 32 bytes: %d", len(a))
	}
	if bytes.Equal(a, c) {
		t.Errorf("FAIL: two purposes share a key")
	}
	if seal, _ := d.seal.load(); bytes.Equal(seal, a) {
		t.Errorf("FAIL: the derived key is the sealing key")
	}
	again := &DB{seal: &sealer{path: d.seal.path}}
	if x, _ := again.DerivedKey("one"); !bytes.Equal(x, a) {
		t.Errorf("FAIL: another open of the same directory derived another key")
	}
	if !t.Failed() {
		t.Log("ok")
	}
}