| 615 | algorithm_name: &str, |
| 616 | hash: &HashAlgorithm, |
| 617 | ) -> Result<(u32, Box<[u8]>, Option<KeyKind>)> { |
| 618 | if let KeyAlgorithmMode::Import { format, kind, data } = mode { |
| 619 | let (mod_length, exp) = import_rsa_key(ctx, format, kind, data, algorithm_name, hash)?; |
| 620 | Ok((mod_length, exp, Some(*kind))) |
| 621 | } else { |
| 622 | let modulus_length = obj.get_required("modulusLength", "algorithm")?; |
| 623 | let public_exponent: TypedArray<u8> = |
| 624 | obj.get_required("publicExponent", "algorithm")?; |
| 625 | let public_exponent = public_exponent |
| 626 | .as_bytes() |
| 627 | .ok_or_else(|| { |
| 628 | DOMException::not_supported_error(ctx, "Array buffer has been detached") |
| 629 | })? |
| 630 | .to_owned() |
| 631 | .into_boxed_slice(); |
| 632 | Ok((modulus_length, public_exponent, None)) |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | #[cfg(not(feature = "_subtle-full"))] |
| 637 | #[inline] |
| 638 | fn import<'js>( |
| 639 | ctx: &Ctx<'js>, |
| 640 | _mode: KeyAlgorithmMode<'_, 'js>, |
| 641 | obj: &Object<'js>, |
| 642 | _algorithm_name: &str, |
| 643 | _hash: &HashAlgorithm, |
| 644 | ) -> Result<(u32, Box<[u8]>, Option<KeyKind>)> { |
| 645 | let modulus_length = obj.get_required("modulusLength", "algorithm")?; |
| 646 | let public_exponent: TypedArray<u8> = obj.get_required("publicExponent", "algorithm")?; |
| 647 | let public_exponent = public_exponent |
| 648 | .as_bytes() |
| 649 | .ok_or_else(|| { |
| 650 | DOMException::not_supported_error(ctx, "Array buffer has been detached") |
| 651 | })? |
| 652 | .to_owned() |
| 653 | .into_boxed_slice(); |
| 654 | Ok((modulus_length, public_exponent, None)) |
| 655 | } |
| 656 | |
| 657 | let (modulus_length, public_exponent, key_kind) = |
| 658 | import(ctx, mode, &obj, algorithm_name, &hash)?; |
| 659 | |
| 660 | if is_generate { |
| 661 | parse_rsa_public_exponent(&public_exponent).or_throw_dom(ctx)?; |
| 662 | } |
| 663 | |
| 664 | KeyUsage::classify_and_check_usages( |
| 665 | ctx, |
| 666 | if algorithm_name == "RSA-OAEP" { |
| 667 | KeyUsageAlgorithm::RsaOaep |
| 668 | } else { |
| 669 | KeyUsageAlgorithm::Sign |
| 670 | }, |
| 671 | usages, |
| 672 | private_usages, |
| 673 | public_usages, |
| 674 | key_kind.as_ref(), |