forked from FiloSottile/torchwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcosignature_test.go
More file actions
38 lines (31 loc) · 849 Bytes
/
Copy pathcosignature_test.go
File metadata and controls
38 lines (31 loc) · 849 Bytes
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
package torchwood_test
import (
"bytes"
"crypto/ed25519"
"crypto/rand"
"testing"
"filippo.io/torchwood"
"golang.org/x/mod/sumdb/note"
)
func TestSignerRoundtrip(t *testing.T) {
_, k, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
s, err := torchwood.NewCosignatureSigner("example.com", k)
if err != nil {
t.Fatal(err)
}
msg := "test\n123\nf+7CoKgXKE/tNys9TTXcr/ad6U/K3xvznmzew9y6SP0=\nextension 1\nextension 2\n"
n, err := note.Sign(¬e.Note{Text: msg}, s)
if err != nil {
t.Fatal(err)
}
if _, err := note.Open(n, note.VerifierList(s.Verifier())); err != nil {
t.Fatal(err)
}
nn := bytes.Replace(n, []byte("extension 2"), []byte("extension X"), 1)
if _, err := note.Open(nn, note.VerifierList(s.Verifier())); err == nil {
t.Fatal("expected error verifying modified note, got nil")
}
}