Skip to content

Commit

Permalink
feat: instances of JWKS.KeyStore are now iterable (e.g. for ... of)
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed May 25, 2019
1 parent 5496a60 commit 2eae293
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/jwks/keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ class KeyStore {
sorted: true
})}`
}

* [Symbol.iterator] () {
for (const key of this.#keys) {
yield key
}
}
}

module.exports = KeyStore
10 changes: 10 additions & 0 deletions test/jwks/keystore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,13 @@ test('.fromJWKS() input validation', t => {
}, { instanceOf: TypeError, message: 'jwks must be a JSON Web Key Set formatted object' })
})
})

test('keystore instance is an iterator', t => {
const ks = new KeyStore()
ks.generateSync('EC')
ks.generateSync('RSA')
for (const key of ks) {
t.truthy(key)
}
t.pass()
})

0 comments on commit 2eae293

Please sign in to comment.