Skip to content

Commit 2eae293

Browse files
committed
feat: instances of JWKS.KeyStore are now iterable (e.g. for ... of)
1 parent 5496a60 commit 2eae293

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/jwks/keystore.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ class KeyStore {
139139
sorted: true
140140
})}`
141141
}
142+
143+
* [Symbol.iterator] () {
144+
for (const key of this.#keys) {
145+
yield key
146+
}
147+
}
142148
}
143149

144150
module.exports = KeyStore

test/jwks/keystore.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,13 @@ test('.fromJWKS() input validation', t => {
199199
}, { instanceOf: TypeError, message: 'jwks must be a JSON Web Key Set formatted object' })
200200
})
201201
})
202+
203+
test('keystore instance is an iterator', t => {
204+
const ks = new KeyStore()
205+
ks.generateSync('EC')
206+
ks.generateSync('RSA')
207+
for (const key of ks) {
208+
t.truthy(key)
209+
}
210+
t.pass()
211+
})

0 commit comments

Comments
 (0)