oficina / meet Public

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

Plain git — no account needed to clone.

Download

Download this file

1package seal
2
3import (
4 "bytes"
5 "testing"
6)
7
8func TestSealRoundTripsAndDiffersPerPurpose(t *testing.T) {
9 s, err := New(bytes.Repeat([]byte{7}, 32))
10 if err != nil {
11 t.Fatal(err)
12 }
13 ct, err := s.SealString(PurposeMeetingTitle, "Board meeting")
14 if err != nil {
15 t.Fatal(err)
16 }
17 if bytes.Contains(ct, []byte("Board")) {
18 t.Fatal("ciphertext contains plaintext")
19 }
20 got, err := s.OpenString(PurposeMeetingTitle, ct)
21 if err != nil || got != "Board meeting" {
22 t.Fatalf("open: %q, %v", got, err)
23 }
24 if _, err := s.OpenString(PurposePendingAddress, ct); err == nil {
25 t.Fatal("a ciphertext opened under the wrong purpose")
26 }
27}
28
29func TestFingerprintIsStableAndKeyed(t *testing.T) {
30 a, _ := New(bytes.Repeat([]byte{1}, 32))
31 b, _ := New(bytes.Repeat([]byte{2}, 32))
32 x1, _ := a.Fingerprint(PurposePendingAddress, "x@example.com")
33 x2, _ := a.Fingerprint(PurposePendingAddress, "x@example.com")
34 y, _ := b.Fingerprint(PurposePendingAddress, "x@example.com")
35 if x1 != x2 {
36 t.Fatal("fingerprint is not stable")
37 }
38 if x1 == y {
39 t.Fatal("fingerprint does not depend on the key")
40 }
41}
42
43func TestNewRefusesWrongKeyLength(t *testing.T) {
44 if _, err := New([]byte("short")); err == nil {
45 t.Fatal("a 5-byte key was accepted")
46 }
47}
48