(ctx: &Ctx<'js>, value: Value<'js>)
| 25 | public_key: Rc<[u8]>, |
| 26 | }, |
| 27 | Derive(KeyDerivation), |
| 28 | } |
| 29 | |
| 30 | impl<'js> FromJs<'js> for DeriveAlgorithm { |
| 31 | fn from_js(ctx: &Ctx<'js>, value: Value<'js>) -> Result<Self> { |
| 32 | let obj = value.into_object_or_throw(ctx, "algorithm")?; |
| 33 | |
| 34 | let name: String = obj.get_required("name", "algorithm")?; |
| 35 | let name = normalize_algorithm_name(&name); |
| 36 | |
| 37 | Ok(match name.as_str() { |
| 38 | "X25519" => { |
| 39 | let public_key: Class<CryptoKey> = obj.get_required("public", "algorithm")?; |
| 40 | let public_key = public_key.borrow(); |
| 41 | |
| 42 | public_key.check_kind(KeyKind::Public).or_throw_dom(ctx)?; |
| 43 | |
| 44 | if !matches!(public_key.algorithm, KeyAlgorithm::X25519) { |
| 45 | return algorithm_invalid_access_error(ctx, &name); |
| 46 | } |
| 47 | |
| 48 | DeriveAlgorithm::X25519 { |
| 49 | public_key: public_key.handle.clone(), |
| 50 | } |
| 51 | }, |
| 52 | "ECDH" => { |
| 53 | let public_key: Class<CryptoKey> = obj.get_required("public", "algorithm")?; |
| 54 | let public_key = public_key.borrow(); |
| 55 | |
| 56 | public_key.check_kind(KeyKind::Public).or_throw_dom(ctx)?; |
| 57 | |
| 58 | if let KeyAlgorithm::Ec { |
| 59 | curve, algorithm, .. |
| 60 | } = &public_key.algorithm |
| 61 | { |
| 62 | DeriveAlgorithm::Ecdh { |
| 63 | curve: *curve, |
| 64 | ec_algorithm: algorithm.clone(), |
| 65 | public_key: public_key.handle.clone(), |
nothing calls this directly
no test coverage detected