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

Method set_session

crates/stdlib/src/openssl.rs:3109–3142  ·  view source on GitHub ↗
(&self, value: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

3107
3108 #[pygetset(setter)]
3109 fn set_session(&self, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
3110 // Check if value is SSLSession type
3111 let session = value
3112 .downcast_ref::<PySslSession>()
3113 .ok_or_else(|| vm.new_type_error("Value is not a SSLSession."))?;
3114
3115 // Check if session refers to the same SSLContext
3116 if !std::ptr::eq(
3117 self.ctx.read().ctx.read().as_ptr(),
3118 session.ctx.ctx.read().as_ptr(),
3119 ) {
3120 return Err(vm.new_value_error("Session refers to a different SSLContext."));
3121 }
3122
3123 // Check if this is a client socket
3124 if self.socket_type != SslServerOrClient::Client {
3125 return Err(vm.new_value_error("Cannot set session for server-side SSLSocket."));
3126 }
3127
3128 // Check if handshake is not finished
3129 let stream = self.connection.read();
3130 unsafe {
3131 if sys::SSL_is_init_finished(stream.ssl().as_ptr()) != 0 {
3132 return Err(vm.new_value_error("Cannot set session after handshake."));
3133 }
3134
3135 let ret = sys::SSL_set_session(stream.ssl().as_ptr(), session.session);
3136 if ret == 0 {
3137 return Err(convert_openssl_error(vm, ErrorStack::get()));
3138 }
3139 }
3140
3141 Ok(())
3142 }
3143
3144 #[pygetset]
3145 fn session_reused(&self) -> bool {

Callers 2

_wrap_socketMethod · 0.45
_wrap_bioMethod · 0.45

Calls 8

convert_openssl_errorFunction · 0.85
getFunction · 0.85
ok_or_elseMethod · 0.80
sslMethod · 0.80
eqFunction · 0.50
ErrClass · 0.50
as_ptrMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected