Skip to content

Commit 4085720

Browse files
Update stdlib/src/ssl.rs
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 36475a3 commit 4085720

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

stdlib/src/ssl.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,17 +1234,17 @@ mod _ssl {
12341234
}
12351235

12361236
#[pymethod]
1237-
fn get_verified_chain(&self, vm: &VirtualMachine) -> Option<PyListRef> {
1237+
fn get_verified_chain(&self, vm: &VirtualMachine) -> PyResult<Option<PyListRef>> {
12381238
let stream = self.stream.read();
12391239
unsafe {
12401240
let chain = sys::SSL_get0_verified_chain(stream.ssl().as_ptr());
12411241
if chain.is_null() {
1242-
return None;
1242+
return Ok(None);
12431243
}
12441244

12451245
let num_certs = sys::OPENSSL_sk_num(chain as *const _);
1246-
let mut certs = Vec::new();
12471246

1247+
let mut certs = Vec::with_capacity(num_certs as usize);
12481248
// Return Certificate objects
12491249
for i in 0..num_certs {
12501250
let cert_ptr = sys::OPENSSL_sk_value(chain as *const _, i) as *mut sys::X509;
@@ -1254,16 +1254,15 @@ mod _ssl {
12541254
// Clone the X509 certificate to create an owned copy
12551255
sys::X509_up_ref(cert_ptr);
12561256
let owned_cert = X509::from_ptr(cert_ptr);
1257-
if let Ok(cert_obj) = cert_to_certificate(vm, owned_cert) {
1258-
certs.push(cert_obj);
1259-
}
1257+
let cert_obj = cert_to_certificate(vm, owned_cert)?;
1258+
certs.push(cert_obj);
12601259
}
12611260

1262-
if certs.is_empty() {
1261+
Ok(if certs.is_empty() {
12631262
None
12641263
} else {
12651264
Some(vm.ctx.new_list(certs))
1266-
}
1265+
})
12671266
}
12681267
}
12691268

@@ -2060,7 +2059,7 @@ mod _ssl {
20602059
// Need to set args[0] = SSL_ERROR_EOF for suppress_ragged_eofs check
20612060
None => {
20622061
return vm.new_exception(
2063-
PySslSyscallError::class(&vm.ctx).to_owned(),
2062+
PySslEOFError::class(&vm.ctx).to_owned(),
20642063
vec![
20652064
vm.ctx.new_int(SSL_ERROR_EOF).into(),
20662065
vm.ctx

stdlib/src/ssl/cert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub(super) use ssl_cert::{PySSLCertificate, cert_to_certificate, cert_to_py, obj
22

33
// Certificate type for SSL module
44

5-
#[pymodule(name = "_ssl")]
5+
#[pymodule(sub)]
66
pub(crate) mod ssl_cert {
77
use crate::{
88
common::ascii,

0 commit comments

Comments
 (0)