oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1package seal
2
3import (
4 "bytes"
5 "testing"
6)
7
8func testDEK() []byte {
9 d := make([]byte, 32)
10 for i := range d {
11 d[i] = byte(i)
12 }
13 return d
14}
15
16func TestSealOpenRoundTrip(t *testing.T) {
17 s, err := New(testDEK())
18 if err != nil {
19 t.Fatal(err)
20 }
21 want := []byte("=SUM(A1:A10)")
22 ct, err := s.Seal("cell.input", want)
23 if err != nil {
24 t.Fatal(err)
25 }
26 if bytes.Contains(ct, want) {
27 t.Fatal("ciphertext contains the plaintext")
28 }
29 got, err := s.Open("cell.input", ct)
30 if err != nil {
31 t.Fatal(err)
32 }
33 if !bytes.Equal(got, want) {
34 t.Fatalf("Open = %q, want %q", got, want)
35 }
36}
37
38// A value sealed under one purpose must not open under another. Purpose
39// separation is what stops a cached value being swapped for an input.
40func TestPurposeSeparation(t *testing.T) {
41 s, _ := New(testDEK())
42 ct, _ := s.Seal("cell.input", []byte("secret"))
43 if _, err := s.Open("cell.cached", ct); err == nil {
44 t.Fatal("opened under the wrong purpose")
45 }
46}
47
48func TestRejectsShortDEK(t *testing.T) {
49 if _, err := New([]byte("too short")); err == nil {
50 t.Fatal("accepted a short DEK")
51 }
52}
53