forked from keybase/saltpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharmor62_sign_test.go
54 lines (48 loc) · 1.25 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
// 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) {
msg := randomMsg(t, 128)
key := newSigPrivKey(t)
smsg, err := SignArmor62(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(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) {
msg := randomMsg(t, 128)
key := newSigPrivKey(t)
sig, err := SignDetachedArmor62(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(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())
}
}