Skip to content

Commit b0f9c28

Browse files
committed
Add SSLContext.compression
1 parent ede2d9e commit b0f9c28

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

vm/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ fn main() {
4949
println!("cargo:rustc-cfg=ossl111");
5050
}
5151
}
52+
if let Ok(v) = env::var("DEP_OPENSSL_CONF") {
53+
for conf in v.split(',') {
54+
println!("cargo:rustc-cfg=osslconf=\"{}\"", conf);
55+
}
56+
}
5257
}
5358

5459
fn git_hash() -> String {

vm/src/stdlib/ssl.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mod sys {
4242
pub fn X509_get_version(x: *const X509) -> c_long;
4343
pub fn SSLv3_method() -> *const SSL_METHOD;
4444
pub fn TLSv1_method() -> *const SSL_METHOD;
45+
pub fn COMP_get_type(meth: *const COMP_METHOD) -> i32;
4546
}
4647
}
4748

@@ -695,6 +696,28 @@ impl PySslSocket {
695696
.map(cipher_to_tuple)
696697
}
697698

699+
#[pymethod]
700+
fn compression(&self) -> Option<&'static str> {
701+
#[cfg(osslconf = "OPENSSL_NO_COMP")]
702+
{
703+
None
704+
}
705+
#[cfg(not(osslconf = "OPENSSL_NO_COMP"))]
706+
{
707+
let stream = self.stream.read();
708+
let comp_method = unsafe { sys::SSL_get_current_compression(stream.ssl().as_ptr()) };
709+
if comp_method.is_null() {
710+
return None;
711+
}
712+
let typ = unsafe { sys::COMP_get_type(comp_method) };
713+
let nid = Nid::from_raw(typ);
714+
if nid == Nid::UNDEF {
715+
return None;
716+
}
717+
nid.short_name().ok()
718+
}
719+
}
720+
698721
#[pymethod]
699722
fn do_handshake(&self, vm: &VirtualMachine) -> PyResult<()> {
700723
let mut stream = self.stream.write();

0 commit comments

Comments
 (0)