Add SSLSocket.cipher

This commit is contained in:
Noah
2021-02-17 21:16:19 -06:00
parent a0d9481fe5
commit ede2d9ed16

View File

@@ -686,6 +686,15 @@ impl PySslSocket {
}
}
#[pymethod]
fn cipher(&self) -> Option<CipherTuple> {
self.stream
.read()
.ssl()
.current_cipher()
.map(cipher_to_tuple)
}
#[pymethod]
fn do_handshake(&self, vm: &VirtualMachine) -> PyResult<()> {
let mut stream = self.stream.write();
@@ -807,6 +816,12 @@ fn convert_ssl_error(
vm.new_exception_msg(cls, msg.to_owned())
}
type CipherTuple = (&'static str, &'static str, i32);
fn cipher_to_tuple(cipher: &ssl::SslCipherRef) -> CipherTuple {
(cipher.name(), cipher.version(), cipher.bits().secret)
}
fn cert_to_py(vm: &VirtualMachine, cert: &X509Ref, binary: bool) -> PyResult {
if binary {
cert.to_der()