-
Notifications
You must be signed in to change notification settings - Fork 64
/
armor62_sign_test.go
62 lines (55 loc) · 1.53 KB
/
armor62_sign_test.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package saltpack
import (
"bytes"
"testing"
)
func testSignArmor62(t *testing.T, version Version) {
msg := randomMsg(t, 128)
key := newSigPrivKey(t)
smsg, err := SignArmor62(version, msg, key, ourBrand)
if err != nil {
t.Fatal(err)
}
if len(smsg) == 0 {
t.Fatal("SignArmor62 returned no error and no output")
}
skey, vmsg, brand, err := Dearmor62Verify(SingleVersionValidator(version), smsg, kr)
if err != nil {
t.Fatal(err)
}
brandCheck(t, brand)
if !PublicKeyEqual(skey, key.GetPublicKey()) {
t.Errorf("signer key %x, expected %x", skey.ToKID(), key.GetPublicKey().ToKID())
}
if !bytes.Equal(vmsg, msg) {
t.Errorf("verified msg '%x', expected '%x'", vmsg, msg)
}
}
func testSignDetachedArmor62(t *testing.T, version Version) {
msg := randomMsg(t, 128)
key := newSigPrivKey(t)
sig, err := SignDetachedArmor62(version, msg, key, ourBrand)
if err != nil {
t.Fatal(err)
}
if len(sig) == 0 {
t.Fatal("empty sig and no error from SignDetachedArmor62")
}
skey, brand, err := Dearmor62VerifyDetached(SingleVersionValidator(version), msg, sig, kr)
if err != nil {
t.Fatal(err)
}
brandCheck(t, brand)
if !PublicKeyEqual(skey, key.GetPublicKey()) {
t.Errorf("signer key %x, expected %x", skey.ToKID(), key.GetPublicKey().ToKID())
}
}
func TestArmor62Sign(t *testing.T) {
tests := []func(*testing.T, Version){
testSignArmor62,
testSignDetachedArmor62,
}
runTestsOverVersions(t, "test", tests)
}