(ctx: &Ctx<'js>, value: Value<'js>)
| 27 | iv: Box<[u8]>, |
| 28 | tag_length: u8, |
| 29 | additional_data: Option<Box<[u8]>>, |
| 30 | }, |
| 31 | RsaOaep { |
| 32 | label: Option<Box<[u8]>>, |
| 33 | }, |
| 34 | AesKw, |
| 35 | } |
| 36 | |
| 37 | impl<'js> FromJs<'js> for EncryptionAlgorithm { |
| 38 | fn from_js(ctx: &Ctx<'js>, value: Value<'js>) -> Result<Self> { |
| 39 | let (name, obj) = to_name_and_maybe_object(ctx, value)?; |
| 40 | let name = normalize_algorithm_name(&name); |
| 41 | |
| 42 | match name.as_str() { |
| 43 | "AES-CBC" => { |
| 44 | let obj = obj?; |
| 45 | let iv = obj |
| 46 | .get_required::<_, ObjectBytes>("iv", "algorithm")? |
| 47 | .into_bytes(ctx)? |
| 48 | .into_boxed_slice(); |
| 49 | |
| 50 | if iv.len() != 16 { |
| 51 | return Err(DOMException::operation_error( |
| 52 | ctx, |
| 53 | "invalid length of iv. Currently supported 16 bytes", |
| 54 | )); |
| 55 | } |
| 56 | |
| 57 | Ok(EncryptionAlgorithm::AesCbc { iv }) |
| 58 | }, |
| 59 | "AES-CTR" => { |
| 60 | let obj = obj?; |
| 61 | let counter = obj |
| 62 | .get_required::<_, ObjectBytes>("counter", "algorithm")? |
| 63 | .into_bytes(ctx)? |
| 64 | .into_boxed_slice(); |
| 65 | |
| 66 | let value = get_required_dictionary_value(&obj, "length", "algorithm")?; |
| 67 | let length = u32::from(enforce_range_u8(ctx, value, "length")?); |
| 68 | |
| 69 | if !matches!(length, 32 | 64 | 128) { |
| 70 | return Err(DOMException::operation_error( |
| 71 | ctx, |
| 72 | "invalid counter length. Currently supported 32/64/128 bits", |
| 73 | )); |
| 74 | } |
| 75 | |
| 76 | Ok(EncryptionAlgorithm::AesCtr { counter, length }) |
| 77 | }, |
| 78 | "AES-GCM" => { |
| 79 | let obj = obj?; |
| 80 | let iv = obj |
| 81 | .get_required::<_, ObjectBytes>("iv", "algorithm")? |
| 82 | .into_bytes(ctx)? |
| 83 | .into_boxed_slice(); |
| 84 | |
| 85 | let additional_data = obj |
| 86 | .get_optional::<_, ObjectBytes>("additionalData")? |
nothing calls this directly
no test coverage detected