Skip to content

Commit

Permalink
Port openssl_version_text to Rust (#10380)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Feb 11, 2024
1 parent e179d30 commit be950bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/cryptography/hazmat/backends/openssl/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,10 @@ def openssl_version_text(self) -> str:
Example: OpenSSL 3.2.1 30 Jan 2024
"""
return self._ffi.string(
self._lib.OpenSSL_version(self._lib.OPENSSL_VERSION)
).decode("ascii")
return rust_openssl.openssl_version_text()

def openssl_version_number(self) -> int:
return self._lib.OpenSSL_version_num()
return rust_openssl.openssl_version()

def _evp_md_from_algorithm(self, algorithm: hashes.HashAlgorithm):
if algorithm.name in ("blake2b", "blake2s"):
Expand Down
2 changes: 2 additions & 0 deletions src/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from cryptography.hazmat.bindings._rust.openssl import (

__all__ = [
"openssl_version",
"openssl_version_text",
"raise_openssl_error",
"aead",
"cmac",
Expand All @@ -45,6 +46,7 @@ __all__ = [
_legacy_provider_loaded: bool

def openssl_version() -> int: ...
def openssl_version_text() -> str: ...
def raise_openssl_error() -> typing.NoReturn: ...
def capture_error_stack() -> list[OpenSSLError]: ...
def is_fips_enabled() -> bool: ...
Expand Down
6 changes: 6 additions & 0 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ fn openssl_version() -> i64 {
openssl::version::number()
}

#[pyo3::prelude::pyfunction]
fn openssl_version_text() -> &'static str {
openssl::version::version()
}

#[pyo3::prelude::pyfunction]
fn is_fips_enabled() -> bool {
cryptography_openssl::fips::is_enabled()
Expand Down Expand Up @@ -107,6 +112,7 @@ fn _rust(py: pyo3::Python<'_>, m: &pyo3::types::PyModule) -> pyo3::PyResult<()>
}
}
openssl_mod.add_function(pyo3::wrap_pyfunction!(openssl_version, m)?)?;
openssl_mod.add_function(pyo3::wrap_pyfunction!(openssl_version_text, m)?)?;
openssl_mod.add_function(pyo3::wrap_pyfunction!(error::raise_openssl_error, m)?)?;
openssl_mod.add_function(pyo3::wrap_pyfunction!(error::capture_error_stack, m)?)?;
openssl_mod.add_function(pyo3::wrap_pyfunction!(is_fips_enabled, m)?)?;
Expand Down

0 comments on commit be950bd

Please sign in to comment.