Skip to content

Commit

Permalink
Migrate asn1 to declrative modules API (#11224)
Browse files Browse the repository at this point in the history
refs #11158
  • Loading branch information
alex authored Jul 9, 2024
1 parent 55e81de commit 67a5215
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
23 changes: 7 additions & 16 deletions src/rust/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use cryptography_x509::name::Name;
use pyo3::pybacked::PyBackedBytes;
use pyo3::types::IntoPyDict;
use pyo3::types::PyAnyMethods;
use pyo3::types::PyModuleMethods;
use pyo3::ToPyObject;

use crate::error::{CryptographyError, CryptographyResult};
Expand Down Expand Up @@ -176,19 +175,11 @@ fn test_parse_certificate(data: &[u8]) -> Result<TestCertificate, CryptographyEr
})
}

pub(crate) fn create_submodule(
py: pyo3::Python<'_>,
) -> pyo3::PyResult<pyo3::Bound<'_, pyo3::types::PyModule>> {
let submod = pyo3::types::PyModule::new_bound(py, "asn1")?;
submod.add_function(pyo3::wrap_pyfunction_bound!(parse_spki_for_data, &submod)?)?;

submod.add_function(pyo3::wrap_pyfunction_bound!(decode_dss_signature, &submod)?)?;
submod.add_function(pyo3::wrap_pyfunction_bound!(encode_dss_signature, &submod)?)?;

submod.add_function(pyo3::wrap_pyfunction_bound!(
test_parse_certificate,
&submod
)?)?;

Ok(submod)
#[pyo3::pymodule]
#[pyo3(name = "asn1")]
pub(crate) mod asn1_mod {
#[pymodule_export]
use super::{
decode_dss_signature, encode_dss_signature, parse_spki_for_data, test_parse_certificate,
};
}
4 changes: 2 additions & 2 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ fn enable_fips(providers: &mut LoadedProviders) -> CryptographyResult<()> {
mod _rust {
use pyo3::types::PyModuleMethods;

#[pymodule_export]
use crate::asn1::asn1_mod;
#[pymodule_export]
use crate::exceptions::exceptions;
#[pymodule_export]
Expand Down Expand Up @@ -185,9 +187,7 @@ mod _rust {

#[pymodule_init]
fn init(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> {
m.add_submodule(&crate::asn1::create_submodule(m.py())?)?;
m.add_submodule(&crate::pkcs7::create_submodule(m.py())?)?;

m.add_submodule(&cryptography_cffi::create_module(m.py())?)?;

Ok(())
Expand Down

0 comments on commit 67a5215

Please sign in to comment.