Skip to content

Commit 31905bd

Browse files
committed
Add OPENSSL_VERSION constants
1 parent 5885898 commit 31905bd

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

@@ -575,6 +577,19 @@ fn convert_ssl_error(vm: &VirtualMachine, e: ssl::Error) -> PyBaseExceptionRef {
575577
}
576578
}
577579

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

594609
// Constants
610+
"OPENSSL_VERSION" => ctx.new_str(openssl::version::version().to_owned()),
611+
"OPENSSL_VERSION_NUMBER" => ctx.new_int(openssl::version::number()),
612+
"OPENSSL_VERSION_INFO" => parse_version_info(openssl::version::number()).into_pyobject(vm).unwrap(),
595613
"PROTOCOL_SSLv2" => ctx.new_int(SslVersion::Ssl2 as u32),
596614
"PROTOCOL_SSLv3" => ctx.new_int(SslVersion::Ssl3 as u32),
597615
"PROTOCOL_SSLv23" => ctx.new_int(SslVersion::Tls as u32),

0 commit comments

Comments
 (0)