Skip to content

Commit

Permalink
Upgrade to pyo3 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jan 8, 2023
1 parent ad1a796 commit 2979a2c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
30 changes: 20 additions & 10 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false

[dependencies]
once_cell = "1"
pyo3 = { version = "0.16" }
pyo3 = { version = "0.17" }
asn1 = { version = "0.13.0", default-features = false }
pem = "1.1"
chrono = { version = "0.4.22", default-features = false, features = ["alloc", "clock"] }
Expand Down
5 changes: 1 addition & 4 deletions src/rust/src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ impl ObjectIdentifier {
slf
}

fn __repr__(&self) -> pyo3::PyResult<String> {
let gil = pyo3::Python::acquire_gil();
let py = gil.python();

fn __repr__(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<String> {
let self_clone = pyo3::PyCell::new(
py,
ObjectIdentifier {
Expand Down
5 changes: 1 addition & 4 deletions src/rust/src/x509/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ impl Certificate {
}
}

fn __repr__(&self) -> pyo3::PyResult<String> {
let gil = pyo3::Python::acquire_gil();
let py = gil.python();

fn __repr__(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<String> {
let subject = self.subject(py)?;
let subject_repr = subject.repr()?.extract::<&str>()?;
Ok(format!("<Certificate(subject={}, ...)>", subject_repr))
Expand Down
9 changes: 5 additions & 4 deletions src/rust/src/x509/crl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ impl CertificateRevocationList {
}
}

fn __getitem__(&self, idx: &pyo3::PyAny) -> pyo3::PyResult<pyo3::PyObject> {
let gil = pyo3::Python::acquire_gil();
let py = gil.python();

fn __getitem__(
&self,
py: pyo3::Python<'_>,
idx: &pyo3::PyAny,
) -> pyo3::PyResult<pyo3::PyObject> {
self.raw.with(|val| {
val.revoked_certs.get_or_init(py, || {
match &val.value.tbs_cert_list.revoked_certificates {
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/x509/ocsp_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl OCSPRequest {

let hashes = py.import("cryptography.hazmat.primitives.hashes")?;
match ocsp::OIDS_TO_HASH.get(&cert_id.hash_algorithm.oid) {
Some(alg_name) => Ok(hashes.getattr(alg_name)?.call0()?),
Some(alg_name) => Ok(hashes.getattr(*alg_name)?.call0()?),
None => {
let exceptions = py.import("cryptography.exceptions")?;
Err(PyAsn1Error::from(pyo3::PyErr::from_value(
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/x509/ocsp_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ impl SingleResponse<'_> {
fn py_hash_algorithm<'p>(&self, py: pyo3::Python<'p>) -> Result<&'p pyo3::PyAny, PyAsn1Error> {
let hashes = py.import("cryptography.hazmat.primitives.hashes")?;
match ocsp::OIDS_TO_HASH.get(&self.cert_id.hash_algorithm.oid) {
Some(alg_name) => Ok(hashes.getattr(alg_name)?.call0()?),
Some(alg_name) => Ok(hashes.getattr(*alg_name)?.call0()?),
None => {
let exceptions = py.import("cryptography.exceptions")?;
Err(PyAsn1Error::from(pyo3::PyErr::from_value(
Expand Down
2 changes: 1 addition & 1 deletion tests/hazmat/primitives/test_pkcs7.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def test_invalid_types(self):
)
with pytest.raises(TypeError):
pkcs7.serialize_certificates(
"not a list of certs", # type: ignore[arg-type]
object(), # type: ignore[arg-type]
serialization.Encoding.PEM,
)

Expand Down

0 comments on commit 2979a2c

Please sign in to comment.