MCPcopy Index your code
hub / github.com/RustPython/RustPython / RAND_bytes

Function RAND_bytes

crates/stdlib/src/ssl.rs:4885–4899  ·  view source on GitHub ↗
(n: i64, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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)> {

Callers 2

rand_pseudo_bytesFunction · 0.85
RAND_pseudo_bytesFunction · 0.85

Calls 5

newFunction · 0.85
new_os_errorMethod · 0.80
ErrClass · 0.50
fillMethod · 0.45
new_bytesMethod · 0.45

Tested by

no test coverage detected