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

Method shared_ciphers

crates/stdlib/src/openssl.rs:2658–2719  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2656
2657 #[pymethod]
2658 fn shared_ciphers(&self, vm: &VirtualMachine) -> Option<PyListRef> {
2659 #[cfg(ossl110)]
2660 {
2661 // Use thread-local SSL pointer during handshake to avoid deadlock
2662 let ssl_ptr = get_ssl_ptr_for_context_change(&self.connection);
2663 unsafe {
2664 let server_ciphers = SSL_get_ciphers(ssl_ptr);
2665 if server_ciphers.is_null() {
2666 return None;
2667 }
2668
2669 let client_ciphers = SSL_get_client_ciphers(ssl_ptr);
2670 if client_ciphers.is_null() {
2671 return None;
2672 }
2673
2674 let mut result = Vec::new();
2675 let num_server = sys::OPENSSL_sk_num(server_ciphers as *const _);
2676 let num_client = sys::OPENSSL_sk_num(client_ciphers as *const _);
2677
2678 for i in 0..num_server {
2679 let server_cipher_ptr = sys::OPENSSL_sk_value(server_ciphers as *const _, i)
2680 as *const sys::SSL_CIPHER;
2681
2682 // Check if client supports this cipher by comparing pointers
2683 let mut found = false;
2684 for j in 0..num_client {
2685 let client_cipher_ptr =
2686 sys::OPENSSL_sk_value(client_ciphers as *const _, j)
2687 as *const sys::SSL_CIPHER;
2688
2689 if server_cipher_ptr == client_cipher_ptr {
2690 found = true;
2691 break;
2692 }
2693 }
2694
2695 if found {
2696 let cipher = ssl::SslCipherRef::from_ptr(server_cipher_ptr as *mut _);
2697 let (name, version, bits) = cipher_to_tuple(cipher);
2698 let tuple = vm.new_tuple((
2699 vm.ctx.new_str(name),
2700 vm.ctx.new_str(version),
2701 vm.ctx.new_int(bits),
2702 ));
2703 result.push(tuple.into());
2704 }
2705 }
2706
2707 if result.is_empty() {
2708 None
2709 } else {
2710 Some(vm.ctx.new_list(result))
2711 }
2712 }
2713 }
2714 #[cfg(not(ossl110))]
2715 {

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
cipher_to_tupleFunction · 0.85
new_listMethod · 0.80
SomeClass · 0.50
new_tupleMethod · 0.45
new_strMethod · 0.45
new_intMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected