MCPcopy Create free account
hub / github.com/Keats/jsonwebtoken / from_jwk

Method from_jwk

src/decoding.rs:213–231  ·  view source on GitHub ↗

If you have a key in Jwk format

(jwk: &Jwk)

Source from the content-addressed store, hash-verified

211
212 /// If you have a key in Jwk format
213 pub fn from_jwk(jwk: &Jwk) -> Result<Self> {
214 match &jwk.algorithm {
215 AlgorithmParameters::RSA(params) => {
216 DecodingKey::from_rsa_components(&params.n, &params.e)
217 }
218 AlgorithmParameters::EllipticCurve(params) => {
219 DecodingKey::from_ec_components(&params.x, &params.y)
220 }
221 AlgorithmParameters::OctetKeyPair(params) => DecodingKey::from_ed_components(&params.x),
222 AlgorithmParameters::OctetKey(params) => {
223 let out = b64_decode(&params.value)?;
224 Ok(DecodingKey {
225 family: AlgorithmFamily::Hmac,
226 kind: DecodingKeyKind::SecretOrDer(out),
227 })
228 }
229 AlgorithmParameters::Other(_) => Err(ErrorKind::UnsupportedAlgorithm.into()),
230 }
231 }
232
233 /// Try to get the key in raw byte format.
234 ///

Callers

nothing calls this directly

Calls 1

b64_decodeFunction · 0.85

Tested by

no test coverage detected