Skip to content

Commit 0794a43

Browse files
committed
minor: add KeysConfiguration.Get
1 parent 25cef28 commit 0794a43

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

kid_keys.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ type (
5757
// Look the MustLoad/Load method.
5858
//
5959
// Example at: _examples/multiple-kids.
60-
KeysConfiguration []struct {
60+
KeysConfiguration []KeyConfiguration
61+
62+
// KeyConfiguration is a single key configuration.
63+
// It's just a representation of the Key struct but with string fields.
64+
KeyConfiguration struct {
6165
ID string `json:"id" yaml:"ID" toml:"ID" ini:"id"`
6266
// Alg declares the algorithm name.
6367
// Available values:
@@ -94,6 +98,17 @@ type (
9498
}
9599
)
96100

101+
// Get returns the key configuration based on its id.
102+
func (c KeysConfiguration) Get(kid string) (KeyConfiguration, bool) {
103+
for _, entry := range c {
104+
if entry.ID == kid {
105+
return entry, true
106+
}
107+
}
108+
109+
return KeyConfiguration{}, false
110+
}
111+
97112
// MustLoad same as Load but it panics if errored.
98113
func (c KeysConfiguration) MustLoad() Keys {
99114
keys, err := c.Load()

0 commit comments

Comments
 (0)