(args: HmacDigestArgs, vm: &VirtualMachine)
| 799 | |
| 800 | #[pyfunction] |
| 801 | fn hmac_digest(args: HmacDigestArgs, vm: &VirtualMachine) -> PyResult<PyBytes> { |
| 802 | let name = resolve_digestmod(&args.digest, vm)?; |
| 803 | |
| 804 | let key_buf = args.key.borrow_buf(); |
| 805 | let msg_buf = args.msg.borrow_buf(); |
| 806 | |
| 807 | macro_rules! do_hmac { |
| 808 | ($hash_ty:ty) => {{ |
| 809 | let mut mac = <hmac::Hmac<$hash_ty> as Mac>::new_from_slice(&key_buf) |
| 810 | .map_err(|_| vm.new_value_error("invalid key length".to_owned()))?; |
| 811 | Mac::update(&mut mac, &msg_buf); |
| 812 | Ok(mac.finalize().into_bytes().to_vec().into()) |
| 813 | }}; |
| 814 | } |
| 815 | |
| 816 | match name.as_str() { |
| 817 | "md5" => do_hmac!(Md5), |
| 818 | "sha1" => do_hmac!(Sha1), |
| 819 | "sha224" => do_hmac!(Sha224), |
| 820 | "sha256" => do_hmac!(Sha256), |
| 821 | "sha384" => do_hmac!(Sha384), |
| 822 | "sha512" => do_hmac!(Sha512), |
| 823 | "sha3_224" => do_hmac!(Sha3_224), |
| 824 | "sha3_256" => do_hmac!(Sha3_256), |
| 825 | "sha3_384" => do_hmac!(Sha3_384), |
| 826 | "sha3_512" => do_hmac!(Sha3_512), |
| 827 | _ => Err(unsupported_hash(&name, vm)), |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | #[pyfunction] |
| 832 | fn pbkdf2_hmac(args: Pbkdf2HmacArgs, vm: &VirtualMachine) -> PyResult<PyBytes> { |
nothing calls this directly
no test coverage detected