-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_dendrite_test.go
More file actions
64 lines (54 loc) · 2.31 KB
/
Copy pathformat_dendrite_test.go
File metadata and controls
64 lines (54 loc) · 2.31 KB
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
63
64
package signing_key
import (
"crypto/ed25519"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDendriteFormatter_RoundTrip(t *testing.T) {
raw := `-----BEGIN MATRIX PRIVATE KEY-----
Key-ID: ed25519:1Pu3u3
1Pu3u3solToI2pTdsHA4wj05bANnzPwJoxPepw2he2s=
-----END MATRIX PRIVATE KEY-----
`
f := &dendriteFormatter{}
key, err := f.decode([]byte(raw))
assert.NoError(t, err)
assert.NotNil(t, key)
encoded, err := f.encode(key)
assert.NoError(t, err)
assert.NotNil(t, encoded)
assert.Equal(t, raw, string(encoded))
}
func TestDendriteFormatter_DecodeAll(t *testing.T) {
raw := `-----BEGIN MATRIX PRIVATE KEY-----
Key-ID: ed25519:1Pu3u3
1Pu3u3solToI2pTdsHA4wj05bANnzPwJoxPepw2he2s=
-----END MATRIX PRIVATE KEY-----
-----BEGIN MATRIX PRIVATE KEY-----
Key-ID: ed25519:wBZqM2
YOA4wuCQ+Wh7Vr+zmYSZpScnrgsrSAVtP89hn0zPO+s=
-----END MATRIX PRIVATE KEY-----
`
single := `-----BEGIN MATRIX PRIVATE KEY-----
Key-ID: ed25519:1Pu3u3
1Pu3u3solToI2pTdsHA4wj05bANnzPwJoxPepw2he2s=
-----END MATRIX PRIVATE KEY-----
`
k1 := ed25519.PrivateKey{0xd4, 0xfb, 0xb7, 0xbb, 0x7b, 0x28, 0x95, 0x3a, 0x8, 0xda, 0x94, 0xdd, 0xb0, 0x70, 0x38, 0xc2, 0x3d, 0x39, 0x6c, 0x3, 0x67, 0xcc, 0xfc, 0x9, 0xa3, 0x13, 0xde, 0xa7, 0xd, 0xa1, 0x7b, 0x6b, 0xb8, 0x16, 0xad, 0x48, 0x46, 0xc1, 0x3b, 0xab, 0xbb, 0x48, 0xdc, 0x2f, 0x37, 0x5, 0x45, 0x8, 0x3e, 0x17, 0x19, 0xa4, 0xb4, 0x8a, 0x43, 0xc8, 0xd4, 0xf3, 0x20, 0x3f, 0x99, 0xe5, 0x87, 0x77}
k2 := ed25519.PrivateKey{0x60, 0xe0, 0x38, 0xc2, 0xe0, 0x90, 0xf9, 0x68, 0x7b, 0x56, 0xbf, 0xb3, 0x99, 0x84, 0x99, 0xa5, 0x27, 0x27, 0xae, 0xb, 0x2b, 0x48, 0x5, 0x6d, 0x3f, 0xcf, 0x61, 0x9f, 0x4c, 0xcf, 0x3b, 0xeb, 0x7, 0x42, 0x98, 0x74, 0x64, 0x7e, 0xd5, 0xfd, 0xee, 0x11, 0x58, 0x1c, 0xa6, 0xd8, 0x1, 0xab, 0x1f, 0x95, 0x2b, 0xd9, 0xbe, 0xec, 0xb7, 0x6c, 0x5f, 0xbd, 0x74, 0xbf, 0xdd, 0x66, 0xe, 0x1c}
f := &dendriteFormatter{}
keys, err := f.decodeAll([]byte(raw))
assert.NoError(t, err)
assert.NotNil(t, keys)
assert.Equal(t, 2, len(keys))
assert.Equal(t, "1Pu3u3", keys[0].KeyVersion)
assert.Equal(t, "wBZqM2", keys[1].KeyVersion)
assert.Equal(t, k1, keys[0].PrivateKey)
assert.Equal(t, k2, keys[1].PrivateKey)
keys, err = f.decodeAll([]byte(single))
assert.NoError(t, err)
assert.NotNil(t, keys)
assert.Equal(t, 1, len(keys))
assert.Equal(t, "1Pu3u3", keys[0].KeyVersion)
assert.Equal(t, k1, keys[0].PrivateKey)
}