-
Notifications
You must be signed in to change notification settings - Fork 3
/
crypto_test.go
40 lines (34 loc) · 915 Bytes
/
crypto_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
package jwker_test
import (
"io/ioutil"
"testing"
"github.com/jphastings/jwker"
"github.com/stretchr/testify/assert"
)
func TestPEM(t *testing.T) {
algos := []string{
"ec", "rsa", "ed25519", "x25519",
"ec.pub", "rsa.pub", "ed25519.pub", "x25519.pub",
}
for _, algo := range algos {
t.Run(algo, func(t *testing.T) {
jwkBytes, err := ioutil.ReadFile("test_data/" + algo + ".jwk")
if err != nil {
t.Fatal("failed to read JWK fixture:", err)
}
pemBytes, err := ioutil.ReadFile("test_data/" + algo + ".pem")
if err != nil {
t.Fatal("failed to read PEM fixture:", err)
}
jwk, err := jwker.ParseJWK(jwkBytes)
if err != nil {
t.Fatal("failed to unmarshal JWK:", err)
}
pem, err := jwk.PEM()
if err != nil {
t.Fatal("failed to convert JWK to PEM:", err)
}
assert.Equal(t, string(pemBytes), string(pem), "output PEM does not match fixture")
})
}
}