...
1
2 package ecc
3
4 import (
5 "bytes"
6 "crypto/rand"
7 "io"
8 "testing"
9 )
10
11
12 func TestEd25519MarshalUnmarshal(t *testing.T) {
13 c := NewEd25519()
14
15 x := make([]byte, ed25519Size)
16 _, err := io.ReadFull(rand.Reader, x)
17 if err != nil {
18 t.Fatal(err)
19 }
20
21 x[0] = 0
22
23 encoded := c.MarshalBytePoint(x)
24 parsed := c.UnmarshalBytePoint(encoded)
25
26 if !bytes.Equal(x, parsed) {
27 t.Fatal("failed to marshal/unmarshal point correctly")
28 }
29
30 encoded = c.MarshalByteSecret(x)
31 parsed = c.UnmarshalByteSecret(encoded)
32
33 if !bytes.Equal(x, parsed) {
34 t.Fatal("failed to marshal/unmarshal secret correctly")
35 }
36 }
37
View as plain text