MCPcopy Create free account
hub / github.com/awslabs/llrt / from_js

Method from_js

modules/llrt_crypto/src/subtle/derive_algorithm.rs:27–62  ·  view source on GitHub ↗
(ctx: &Ctx<'js>, value: Value<'js>)

Source from the content-addressed store, hash-verified

25 public_key: Rc<[u8]>,
26 },
27 Derive(KeyDerivation),
28}
29
30impl<'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(),

Callers

nothing calls this directly

Calls 6

algorithm_mismatch_errorFunction · 0.85
into_object_or_throwMethod · 0.80
get_requiredMethod · 0.80
as_strMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected