From 243354d4c7ff6282fc2db98e97a40d6668f37cd4 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 9 Jul 2024 19:16:20 -0400 Subject: [PATCH] Migrate `certificate` to declarative modules API refs #11158 --- src/rust/src/lib.rs | 6 +++++- src/rust/src/x509/certificate.rs | 31 ++++--------------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index e4285fce2b981..f0e0f5ca54a12 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -107,6 +107,11 @@ mod _rust { #[pyo3::pymodule] mod x509 { + #[pymodule_export] + use crate::x509::certificate::{ + create_x509_certificate, load_der_x509_certificate, load_pem_x509_certificate, + load_pem_x509_certificates, Certificate, + }; #[pymodule_export] use crate::x509::verify::{ PolicyBuilder, PyClientVerifier, PyServerVerifier, PyStore, PyVerifiedClient, @@ -115,7 +120,6 @@ mod _rust { #[pymodule_init] fn init(x509_mod: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> { - crate::x509::certificate::add_to_module(x509_mod)?; crate::x509::common::add_to_module(x509_mod)?; crate::x509::crl::add_to_module(x509_mod)?; crate::x509::csr::add_to_module(x509_mod)?; diff --git a/src/rust/src/x509/certificate.rs b/src/rust/src/x509/certificate.rs index 2fb5d5af272ed..810d7aa991c62 100644 --- a/src/rust/src/x509/certificate.rs +++ b/src/rust/src/x509/certificate.rs @@ -17,7 +17,7 @@ use cryptography_x509::extensions::{ use cryptography_x509::extensions::{Extension, SubjectAlternativeName}; use cryptography_x509::{common, oid}; use cryptography_x509_verification::ops::CryptoOps; -use pyo3::types::{PyAnyMethods, PyListMethods, PyModuleMethods}; +use pyo3::types::{PyAnyMethods, PyListMethods}; use pyo3::{IntoPy, ToPyObject}; use crate::asn1::{ @@ -366,7 +366,7 @@ fn cert_version( #[pyo3::pyfunction] #[pyo3(signature = (data, backend=None))] -fn load_pem_x509_certificate( +pub(crate) fn load_pem_x509_certificate( py: pyo3::Python<'_>, data: &[u8], backend: Option>, @@ -388,7 +388,7 @@ fn load_pem_x509_certificate( } #[pyo3::pyfunction] -fn load_pem_x509_certificates( +pub(crate) fn load_pem_x509_certificates( py: pyo3::Python<'_>, data: &[u8], ) -> CryptographyResult> { @@ -886,7 +886,7 @@ pub(crate) fn time_from_datetime(dt: asn1::DateTime) -> CryptographyResult, builder: &pyo3::Bound<'_, pyo3::PyAny>, private_key: &pyo3::Bound<'_, pyo3::PyAny>, @@ -975,26 +975,3 @@ pub(crate) fn set_bit(vals: &mut [u8], n: usize, set: bool) { vals[idx] |= v; } } - -pub(crate) fn add_to_module(module: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> { - module.add_function(pyo3::wrap_pyfunction_bound!( - load_der_x509_certificate, - module - )?)?; - module.add_function(pyo3::wrap_pyfunction_bound!( - load_pem_x509_certificate, - module - )?)?; - module.add_function(pyo3::wrap_pyfunction_bound!( - load_pem_x509_certificates, - module - )?)?; - module.add_function(pyo3::wrap_pyfunction_bound!( - create_x509_certificate, - module - )?)?; - - module.add_class::()?; - - Ok(()) -}