Skip to content

Commit a61f0ed

Browse files
committed
Add OPENSSL_VERSION constants
1 parent 21aeec7 commit a61f0ed

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Lib/ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
import _ssl # if we can't import it, let the error propagate
102102

103103
# XXX RustPython TODO: provide more of these imports
104-
# from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
104+
from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
105105
from _ssl import _SSLContext #, MemoryBIO, SSLSession
106106
from _ssl import (
107107
SSLError, #SSLZeroReturnError, SSLWantReadError, SSLWantWriteError,

vm/src/stdlib/ssl.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use crate::obj::objbyteinner::PyBytesLike;
66
use crate::obj::objbytes::PyBytesRef;
77
use crate::obj::objstr::{PyString, PyStringRef};
88
use crate::obj::{objtype::PyClassRef, objweakref::PyWeak};
9-
use crate::pyobject::{PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject};
9+
use crate::pyobject::{
10+
IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
11+
};
1012
use crate::types::create_type;
1113
use crate::VirtualMachine;
1214

@@ -577,6 +579,19 @@ fn convert_ssl_error(vm: &VirtualMachine, e: ssl::Error) -> PyBaseExceptionRef {
577579
}
578580
}
579581

582+
fn parse_version_info(mut n: i64) -> (u8, u8, u8, u8, u8) {
583+
let status = (n & 0xF) as u8;
584+
n >>= 4;
585+
let patch = (n & 0xFF) as u8;
586+
n >>= 8;
587+
let fix = (n & 0xFF) as u8;
588+
n >>= 8;
589+
let minor = (n & 0xFF) as u8;
590+
n >>= 8;
591+
let major = (n & 0xFF) as u8;
592+
(major, minor, fix, patch, status)
593+
}
594+
580595
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
581596
openssl::init();
582597
let ctx = &vm.ctx;
@@ -594,6 +609,9 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
594609
"get_default_verify_paths" => ctx.new_function(ssl_get_default_verify_paths),
595610

596611
// Constants
612+
"OPENSSL_VERSION" => ctx.new_str(openssl::version::version().to_owned()),
613+
"OPENSSL_VERSION_NUMBER" => ctx.new_int(openssl::version::number()),
614+
"OPENSSL_VERSION_INFO" => parse_version_info(openssl::version::number()).into_pyobject(vm).unwrap(),
597615
"PROTOCOL_SSLv2" => ctx.new_int(SslVersion::Ssl2 as u32),
598616
"PROTOCOL_SSLv3" => ctx.new_int(SslVersion::Ssl3 as u32),
599617
"PROTOCOL_SSLv23" => ctx.new_int(SslVersion::Tls as u32),

0 commit comments

Comments
 (0)