Skip to content

Commit

Permalink
Migrate rsa to declarative modules API
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jul 10, 2024
1 parent 56bab5e commit 7b83826
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
8 changes: 0 additions & 8 deletions src/rust/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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;

pub(crate) mod aead;
pub(crate) mod cipher_registry;
pub(crate) mod ciphers;
Expand All @@ -24,9 +22,3 @@ pub(crate) mod utils;
pub(crate) mod x25519;
#[cfg(all(not(CRYPTOGRAPHY_IS_LIBRESSL), not(CRYPTOGRAPHY_IS_BORINGSSL)))]
pub(crate) mod x448;

pub(crate) fn add_to_module(module: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> {
module.add_submodule(&rsa::create_module(module.py())?)?;

Ok(())
}
20 changes: 7 additions & 13 deletions src/rust/src/backend/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::backend::{hashes, utils};
use crate::buf::CffiBuf;
use crate::error::{CryptographyError, CryptographyResult};
use crate::{exceptions, types};
use pyo3::types::{PyAnyMethods, PyModuleMethods};
use pyo3::types::PyAnyMethods;

#[pyo3::pyclass(
frozen,
Expand Down Expand Up @@ -814,16 +814,10 @@ impl RsaPublicNumbers {
}
}

pub(crate) fn create_module(
py: pyo3::Python<'_>,
) -> pyo3::PyResult<pyo3::Bound<'_, pyo3::types::PyModule>> {
let m = pyo3::types::PyModule::new_bound(py, "rsa")?;
m.add_function(pyo3::wrap_pyfunction_bound!(generate_private_key, &m)?)?;

m.add_class::<RsaPrivateKey>()?;
m.add_class::<RsaPublicKey>()?;
m.add_class::<RsaPrivateNumbers>()?;
m.add_class::<RsaPublicNumbers>()?;

Ok(m)
#[pyo3::pymodule]
pub(crate) mod rsa {
#[pymodule_export]
use super::{
generate_private_key, RsaPrivateKey, RsaPrivateNumbers, RsaPublicKey, RsaPublicNumbers,
};
}
4 changes: 2 additions & 2 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ mod _rust {
#[pymodule_export]
use crate::backend::poly1305::poly1305;
#[pymodule_export]
use crate::backend::rsa::rsa;
#[pymodule_export]
use crate::backend::x25519::x25519;
#[cfg(all(not(CRYPTOGRAPHY_IS_LIBRESSL), not(CRYPTOGRAPHY_IS_BORINGSSL)))]
#[pymodule_export]
Expand Down Expand Up @@ -219,8 +221,6 @@ mod _rust {
}
}

crate::backend::add_to_module(openssl_mod)?;

Ok(())
}
}
Expand Down

0 comments on commit 7b83826

Please sign in to comment.