Skip to content

Commit bf3a665

Browse files
committed
minor: add KeyConfiguration.Clone and KeysConfiguration.Clone helpers
1 parent 2d9ecc4 commit bf3a665

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

kid_keys.go

+22
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ type (
103103
}
104104
)
105105

106+
// Clone returns a new copy of the KeyConfiguration.
107+
func (c KeyConfiguration) Clone() KeyConfiguration {
108+
return KeyConfiguration{
109+
ID: c.ID,
110+
Alg: c.Alg,
111+
Private: c.Private,
112+
Public: c.Public,
113+
MaxAge: c.MaxAge,
114+
EncryptionKey: c.EncryptionKey,
115+
}
116+
}
117+
118+
// Clone returns a new copy of the KeysConfiguration.
119+
// Load or MustLoad must be called to parse the keys after the clone.
120+
func (c KeysConfiguration) Clone() KeysConfiguration {
121+
cloned := make(KeysConfiguration, len(c))
122+
for i, v := range c {
123+
cloned[i] = v.Clone()
124+
}
125+
return cloned
126+
}
127+
106128
// Get returns the key configuration based on its id.
107129
func (c KeysConfiguration) Get(kid string) (KeyConfiguration, bool) {
108130
for _, entry := range c {

0 commit comments

Comments
 (0)