(n: i64, vm: &VirtualMachine)
| 4883 | |
| 4884 | #[pyfunction] |
| 4885 | fn RAND_bytes(n: i64, vm: &VirtualMachine) -> PyResult<PyBytesRef> { |
| 4886 | use aws_lc_rs::rand::{SecureRandom, SystemRandom}; |
| 4887 | |
| 4888 | // Validate n is not negative |
| 4889 | if n < 0 { |
| 4890 | return Err(vm.new_value_error("num must be positive")); |
| 4891 | } |
| 4892 | |
| 4893 | let n_usize = n as usize; |
| 4894 | let rng = SystemRandom::new(); |
| 4895 | let mut buf = vec![0u8; n_usize]; |
| 4896 | rng.fill(&mut buf) |
| 4897 | .map_err(|_| vm.new_os_error("Failed to generate random bytes"))?; |
| 4898 | Ok(PyBytesRef::from(vm.ctx.new_bytes(buf))) |
| 4899 | } |
| 4900 | |
| 4901 | #[pyfunction] |
| 4902 | fn RAND_pseudo_bytes(n: i64, vm: &VirtualMachine) -> PyResult<(PyBytesRef, bool)> { |
no test coverage detected