Skip to content

Commit

Permalink
Migrate keys to declarative modules API (#11236)
Browse files Browse the repository at this point in the history
refs #11158
  • Loading branch information
alex committed Jul 10, 2024
1 parent d67998f commit ccae9ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/rust/src/backend/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 2.0, and the BSD License. See the LICENSE file in the root of this repository
// for complete details.

use pyo3::types::PyModuleMethods;
use pyo3::IntoPy;

use crate::backend::utils;
Expand Down Expand Up @@ -221,17 +220,12 @@ fn public_key_from_pkey(
}
}

pub(crate) fn create_module(
py: pyo3::Python<'_>,
) -> pyo3::PyResult<pyo3::Bound<'_, pyo3::types::PyModule>> {
let m = pyo3::types::PyModule::new_bound(py, "keys")?;

m.add_function(pyo3::wrap_pyfunction_bound!(load_pem_private_key, &m)?)?;
m.add_function(pyo3::wrap_pyfunction_bound!(load_der_private_key, &m)?)?;
m.add_function(pyo3::wrap_pyfunction_bound!(load_der_public_key, &m)?)?;
m.add_function(pyo3::wrap_pyfunction_bound!(load_pem_public_key, &m)?)?;

Ok(m)
#[pyo3::pymodule]
pub(crate) mod keys {
#[pymodule_export]
use super::{
load_der_private_key, load_der_public_key, load_pem_private_key, load_pem_public_key,
};
}

#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion src/rust/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub(crate) fn add_to_module(module: &pyo3::Bound<'_, pyo3::types::PyModule>) ->
module.add_submodule(&dh::create_module(module.py())?)?;
module.add_submodule(&dsa::create_module(module.py())?)?;
module.add_submodule(&ec::create_module(module.py())?)?;
module.add_submodule(&keys::create_module(module.py())?)?;

module.add_submodule(&ed25519::create_module(module.py())?)?;
#[cfg(all(not(CRYPTOGRAPHY_IS_LIBRESSL), not(CRYPTOGRAPHY_IS_BORINGSSL)))]
Expand Down
2 changes: 2 additions & 0 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ mod _rust {
#[pymodule_export]
use super::super::{is_fips_enabled, openssl_version, openssl_version_text};
#[pymodule_export]
use crate::backend::keys::keys;
#[pymodule_export]
use crate::error::{capture_error_stack, raise_openssl_error, OpenSSLError};

#[pymodule_init]
Expand Down

0 comments on commit ccae9ef

Please sign in to comment.