-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature_test.go
35 lines (26 loc) · 923 Bytes
/
signature_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
package lamport
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test(t *testing.T) {
t.Run("signed message can be verified", func(t *testing.T) {
auth := NewOneTimeSignature()
message := MakeMessage()
signature, err := auth.Sign(MakeMessage())
assert.NoError(t, err, "on first time usage there should be no errors")
assert.Equal(t, 256, len(signature))
assert.True(t, OneTimeSignVerify(message, *signature, auth.PublicKey()))
})
t.Run("malformed message is not verified", func(t *testing.T) {
auth := NewOneTimeSignature()
message := MakeMessage()
signature, err := auth.Sign(message)
assert.NoError(t, err, "on first time usage there should be no errors")
assert.Equal(t, 256, len(signature))
malformed := []byte(message[:])
malformed[1] = byte(0)
malformed[2] = byte(1)
assert.False(t, OneTimeSignVerify([32]byte(malformed), *signature, auth.PublicKey()))
})
}