@@ -423,12 +423,25 @@ impl Jwk {
423423 self . common . key_algorithm . unwrap ( ) . to_algorithm ( ) . is_ok ( )
424424 }
425425
426- pub fn from_encoding_key (
427- key : & EncodingKey ,
428- algorithm : Algorithm ,
429- ) -> crate :: errors:: Result < Self > {
426+ pub fn from_encoding_key ( key : & EncodingKey , alg : Algorithm ) -> crate :: errors:: Result < Self > {
430427 Ok ( Self {
431- common : CommonParameters :: default ( ) ,
428+ common : CommonParameters {
429+ key_algorithm : Some ( match alg {
430+ Algorithm :: HS256 => KeyAlgorithm :: HS256 ,
431+ Algorithm :: HS384 => KeyAlgorithm :: HS384 ,
432+ Algorithm :: HS512 => KeyAlgorithm :: HS512 ,
433+ Algorithm :: ES256 => KeyAlgorithm :: ES256 ,
434+ Algorithm :: ES384 => KeyAlgorithm :: ES384 ,
435+ Algorithm :: RS256 => KeyAlgorithm :: RS256 ,
436+ Algorithm :: RS384 => KeyAlgorithm :: RS384 ,
437+ Algorithm :: RS512 => KeyAlgorithm :: RS512 ,
438+ Algorithm :: PS256 => KeyAlgorithm :: PS256 ,
439+ Algorithm :: PS384 => KeyAlgorithm :: PS384 ,
440+ Algorithm :: PS512 => KeyAlgorithm :: PS512 ,
441+ Algorithm :: EdDSA => KeyAlgorithm :: EdDSA ,
442+ } ) ,
443+ ..Default :: default ( )
444+ } ,
432445 algorithm : match key. family {
433446 crate :: algorithms:: AlgorithmFamily :: Hmac => {
434447 AlgorithmParameters :: OctetKey ( OctetKeyParameters {
@@ -451,15 +464,15 @@ impl Jwk {
451464 crate :: algorithms:: AlgorithmFamily :: Ec => {
452465 let rng = rand:: SystemRandom :: new ( ) ;
453466 let key_pair = signature:: EcdsaKeyPair :: from_pkcs8 (
454- alg_to_ec_signing ( algorithm ) ,
467+ alg_to_ec_signing ( alg ) ,
455468 & key. content ,
456469 & rng,
457470 ) ?;
458471 // Ring has this as `ring::ec::suite_b::curve::P384.elem_scalar_seed_len` but
459472 // it's private and not exposed via any methods AFAICT.
460473 let pub_elem_bytes;
461474 let curve;
462- match algorithm {
475+ match alg {
463476 Algorithm :: ES256 => {
464477 pub_elem_bytes = 32 ;
465478 curve = EllipticCurve :: P256 ;
0 commit comments