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

Method _wrap_bio

crates/stdlib/src/ssl.rs:1919–1987  ·  view source on GitHub ↗
(
            zelf: PyRef<Self>,
            args: WrapBioArgs,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1917
1918 #[pymethod]
1919 fn _wrap_bio(
1920 zelf: PyRef<Self>,
1921 args: WrapBioArgs,
1922 vm: &VirtualMachine,
1923 ) -> PyResult<PyRef<PySSLSocket>> {
1924 // Convert server_hostname to Option<String>
1925 // Handle both missing argument and None value
1926 let hostname = match args.server_hostname.into_option().flatten() {
1927 Some(hostname_str) => {
1928 let hostname = hostname_str.as_str();
1929 validate_hostname(hostname, vm)?;
1930 Some(hostname.to_string())
1931 }
1932 None => None,
1933 };
1934
1935 // Extract server_side value
1936 let server_side = args.server_side.unwrap_or(false);
1937
1938 // Validate socket type and context protocol
1939 if server_side && zelf.protocol == PROTOCOL_TLS_CLIENT {
1940 return Err(vm
1941 .new_os_subtype_error(
1942 PySSLError::class(&vm.ctx).to_owned(),
1943 None,
1944 "Cannot create a server socket with a PROTOCOL_TLS_CLIENT context",
1945 )
1946 .upcast());
1947 }
1948 if !server_side && zelf.protocol == PROTOCOL_TLS_SERVER {
1949 return Err(vm
1950 .new_os_subtype_error(
1951 PySSLError::class(&vm.ctx).to_owned(),
1952 None,
1953 "Cannot create a client socket with a PROTOCOL_TLS_SERVER context",
1954 )
1955 .upcast());
1956 }
1957
1958 // Create _SSLSocket instance with BIO mode
1959 let ssl_socket = PySSLSocket {
1960 sock: vm.ctx.none(), // No socket in BIO mode
1961 context: PyRwLock::new(zelf),
1962 server_side,
1963 server_hostname: PyRwLock::new(hostname),
1964 connection: PyMutex::new(None),
1965 handshake_done: PyMutex::new(false),
1966 session_was_reused: PyMutex::new(false),
1967 owner: PyRwLock::new(args.owner.into_option()),
1968 // Filter out Python None objects - only store actual SSLSession objects
1969 session: PyRwLock::new(args.session.into_option().filter(|s| !vm.is_none(s))),
1970 verified_chain: PyRwLock::new(None),
1971 incoming_bio: Some(args.incoming),
1972 outgoing_bio: Some(args.outgoing),
1973 sni_state: PyRwLock::new(None),
1974 pending_context: PyRwLock::new(None),
1975 client_hello_buffer: PyMutex::new(None),
1976 shutdown_state: PyMutex::new(ShutdownState::NotStarted),

Callers 1

_createMethod · 0.45

Calls 15

validate_hostnameFunction · 0.85
newFunction · 0.85
into_optionMethod · 0.80
to_stringMethod · 0.80
upcastMethod · 0.80
new_os_subtype_errorMethod · 0.80
noneMethod · 0.80
into_ref_with_typeMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
flattenMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected