-
Notifications
You must be signed in to change notification settings - Fork 458
/
commontypes.go
75 lines (68 loc) · 1.66 KB
/
commontypes.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package jwtkey
import (
plugintypes "github.com/spiffe/spire-plugin-sdk/proto/spire/plugin/types"
"github.com/spiffe/spire/proto/spire/common"
)
func FromCommonProto(pb *common.PublicKey) (JWTKey, error) {
return fromProtoFields(pb.Kid, pb.PkixBytes, pb.NotAfter)
}
func FromCommonProtos(pbs []*common.PublicKey) ([]JWTKey, error) {
if pbs == nil {
return nil, nil
}
jwtKeys := make([]JWTKey, 0, len(pbs))
for _, pb := range pbs {
jwtKey, err := FromCommonProto(pb)
if err != nil {
return nil, err
}
jwtKeys = append(jwtKeys, jwtKey)
}
return jwtKeys, nil
}
func ToCommonProto(jwtKey JWTKey) (*common.PublicKey, error) {
id, publicKey, expiresAt, err := toProtoFields(jwtKey)
if err != nil {
return nil, err
}
return &common.PublicKey{
Kid: id,
PkixBytes: publicKey,
NotAfter: expiresAt,
}, nil
}
func ToCommonProtos(jwtKeys []JWTKey) ([]*common.PublicKey, error) {
if jwtKeys == nil {
return nil, nil
}
pbs := make([]*common.PublicKey, 0, len(jwtKeys))
for _, jwtKey := range jwtKeys {
pb, err := ToCommonProto(jwtKey)
if err != nil {
return nil, err
}
pbs = append(pbs, pb)
}
return pbs, nil
}
func ToCommonFromPluginProto(pb *plugintypes.JWTKey) (*common.PublicKey, error) {
jwtKey, err := FromPluginProto(pb)
if err != nil {
return nil, err
}
return ToCommonProto(jwtKey)
}
func ToCommonFromPluginProtos(pbs []*plugintypes.JWTKey) ([]*common.PublicKey, error) {
if pbs == nil {
return nil, nil
}
jwtKeys := make([]*common.PublicKey, 0, len(pbs))
for _, pb := range pbs {
jwtKey, err := ToCommonFromPluginProto(pb)
if err != nil {
return nil, err
}
jwtKeys = append(jwtKeys, jwtKey)
}
return jwtKeys, nil
}