In [_Converting an `x5c` from a JSON Web Key to a PEM with Ruby_]({{<ref2020-01-15-x5c-to-pem-ruby>}}) I spoke about how to parse the `x5c` parameter to a PEM encode cert.
However, I've found that taking a whole JWKS and extracting out the certs it references is also something that's useful to do.
As the whole point of the `x5c` is that it can provide a full chain, we should be able to handle [an example JWKS](https://tools.ietf.org/id/draft-miller-jose-pkix-key-00.html#rfc.section.3.1):
The below script will create `somekey_0.pem` for the leaf cert, `somekey_1.pem` for the next cert, and so on, by running `ruby x5c-to-pems.rb filename.jwks`: