Skip to content

Commit

Permalink
rust: use subject() and issuer() APIs
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodruff <[email protected]>
  • Loading branch information
woodruffw committed Jul 26, 2023
1 parent f01254a commit 705de99
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
12 changes: 4 additions & 8 deletions src/rust/src/x509/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,14 @@ impl Certificate {

#[getter]
fn issuer<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<&'p pyo3::PyAny> {
Ok(
x509::parse_name(py, &self.raw.borrow_dependent().tbs_cert.issuer)
.map_err(|e| e.add_location(asn1::ParseLocation::Field("issuer")))?,
)
Ok(x509::parse_name(py, &self.raw.borrow_dependent().issuer())
.map_err(|e| e.add_location(asn1::ParseLocation::Field("issuer")))?)
}

#[getter]
fn subject<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<&'p pyo3::PyAny> {
Ok(
x509::parse_name(py, &self.raw.borrow_dependent().tbs_cert.subject)
.map_err(|e| e.add_location(asn1::ParseLocation::Field("subject")))?,
)
Ok(x509::parse_name(py, &self.raw.borrow_dependent().subject())
.map_err(|e| e.add_location(asn1::ParseLocation::Field("subject")))?)
}

#[getter]
Expand Down
8 changes: 4 additions & 4 deletions src/rust/src/x509/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cryptography_x509::common::{Asn1ReadableOrWritable, AttributeTypeValue, RawT
use cryptography_x509::extensions::{
AccessDescription, DuplicateExtensionsError, Extension, Extensions, RawExtensions,
};
use cryptography_x509::name::{GeneralName, Name, OtherName, UnvalidatedIA5String};
use cryptography_x509::name::{GeneralName, Name, NameReadable, OtherName, UnvalidatedIA5String};
use pyo3::types::IntoPyDict;
use pyo3::{IntoPy, ToPyObject};

Expand Down Expand Up @@ -175,11 +175,11 @@ pub(crate) fn encode_access_descriptions<'a>(

pub(crate) fn parse_name<'p>(
py: pyo3::Python<'p>,
name: &Name<'_>,
name: &NameReadable<'_>,
) -> Result<&'p pyo3::PyAny, CryptographyError> {
let x509_module = py.import(pyo3::intern!(py, "cryptography.x509"))?;
let py_rdns = pyo3::types::PyList::empty(py);
for rdn in name.unwrap_read().clone() {
for rdn in name.clone() {
let py_rdn = parse_rdn(py, &rdn)?;
py_rdns.append(py_rdn)?;
}
Expand Down Expand Up @@ -274,7 +274,7 @@ pub(crate) fn parse_general_name(
.call_method1(pyo3::intern!(py, "_init_without_validation"), (data.0,))?
.to_object(py),
GeneralName::DirectoryName(data) => {
let py_name = parse_name(py, &data)?;
let py_name = parse_name(py, &data.unwrap_read())?;
x509_module
.call_method1(pyo3::intern!(py, "DirectoryName"), (py_name,))?
.to_object(py)
Expand Down
7 changes: 6 additions & 1 deletion src/rust/src/x509/crl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ impl CertificateRevocationList {
fn issuer<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<&'p pyo3::PyAny> {
Ok(x509::parse_name(
py,
&self.owned.borrow_dependent().tbs_cert_list.issuer,
&self
.owned
.borrow_dependent()
.tbs_cert_list
.issuer
.unwrap_read(),
)?)
}

Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/x509/csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl CertificateSigningRequest {
fn subject<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<&'p pyo3::PyAny> {
Ok(x509::parse_name(
py,
&self.raw.borrow_dependent().csr_info.subject,
&self.raw.borrow_dependent().csr_info.subject.unwrap_read(),
)?)
}

Expand Down
4 changes: 3 additions & 1 deletion src/rust/src/x509/ocsp_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ impl OCSPResponse {
fn responder_name<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<&'p pyo3::PyAny> {
let resp = self.requires_successful_response()?;
match resp.tbs_response_data.responder_id {
ocsp_resp::ResponderId::ByName(ref name) => Ok(x509::parse_name(py, name)?),
ocsp_resp::ResponderId::ByName(ref name) => {
Ok(x509::parse_name(py, name.unwrap_read())?)
}
ocsp_resp::ResponderId::ByKey(_) => Ok(py.None().into_ref(py)),
}
}
Expand Down

0 comments on commit 705de99

Please sign in to comment.