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

Method extract_password_bytes

crates/stdlib/src/openssl.rs:1972–1988  ·  view source on GitHub ↗

Helper to extract password bytes from string/bytes/bytearray

(
            obj: &PyObject,
            bad_type_error: &str,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1970
1971 // Helper to extract password bytes from string/bytes/bytearray
1972 fn extract_password_bytes(
1973 obj: &PyObject,
1974 bad_type_error: &str,
1975 vm: &VirtualMachine,
1976 ) -> PyResult<Vec<u8>> {
1977 use crate::vm::builtins::{PyByteArray, PyBytes, PyStr};
1978
1979 if let Some(s) = obj.downcast_ref::<PyStr>() {
1980 Ok(s.as_str().as_bytes().to_vec())
1981 } else if let Some(b) = obj.downcast_ref::<PyBytes>() {
1982 Ok(b.as_bytes().to_vec())
1983 } else if let Some(ba) = obj.downcast_ref::<PyByteArray>() {
1984 Ok(ba.borrow_buf().to_vec())
1985 } else {
1986 Err(vm.new_type_error(bad_type_error.to_owned()))
1987 }
1988 }
1989
1990 // Helper function to create SSL socket
1991 // = CPython's newPySSLSocket()

Callers

nothing calls this directly

Calls 6

to_vecMethod · 0.80
ErrClass · 0.50
as_bytesMethod · 0.45
as_strMethod · 0.45
borrow_bufMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected