Skip to content

Commit 6fa70bd

Browse files
Update pyo3 to 0.26 and other dependencies
Co-authored-by: william <[email protected]>
1 parent be705d1 commit 6fa70bd

File tree

3 files changed

+44
-129
lines changed

3 files changed

+44
-129
lines changed

Cargo.lock

Lines changed: 34 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
99

1010
[dependencies]
1111
openssl = { version = "0.10", features = ["vendored"] }
12-
pyo3 = { version = "0.20", features = ["extension-module"] }
12+
pyo3 = { version = "0.26", features = ["extension-module"] }
1313

1414

1515
[features]

src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use openssl::x509::{X509Ref, X509};
1414
use pyo3::create_exception;
1515
use pyo3::exceptions::PyException;
1616
use pyo3::prelude::*;
17-
use pyo3::types::PyBytes;
17+
use pyo3::types::{PyBytes, PyModule};
1818
use pyo3::wrap_pymodule;
1919

2020
fn _sign(
@@ -108,7 +108,7 @@ fn material_from_sources(
108108
std::fs::read(path).map_err(|err| CertificateError::new_err(err.to_string()))
109109
}
110110
(None, Some(obj)) => {
111-
let obj = obj.as_ref(py);
111+
let obj = obj.bind(py);
112112

113113
if let Ok(value) = obj.extract::<&str>() {
114114
Ok(value.as_bytes().to_vec())
@@ -130,7 +130,7 @@ fn material_from_sources(
130130
}
131131

132132
#[pymodule]
133-
fn exceptions(py: Python, m: &PyModule) -> PyResult<()> {
133+
fn exceptions(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
134134
m.add("RsmimeError", py.get_type::<RsmimeError>())?;
135135
m.add("CertificateError", py.get_type::<CertificateError>())?;
136136
m.add(
@@ -143,14 +143,16 @@ fn exceptions(py: Python, m: &PyModule) -> PyResult<()> {
143143
}
144144

145145
#[pymodule]
146-
fn rsmime(py: Python, m: &PyModule) -> PyResult<()> {
146+
fn rsmime(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
147147
let exceptions = wrap_pymodule!(exceptions);
148148

149149
py.import("sys")?
150150
.getattr("modules")?
151151
.set_item("rsmime.exceptions", exceptions(py))?;
152152

153-
m.add_wrapped(exceptions)?;
153+
let exc_py = exceptions(py);
154+
let exc_bound = exc_py.bind(py);
155+
m.add_submodule(&exc_bound)?;
154156
m.add_class::<Rsmime>()?;
155157

156158
Ok(())
@@ -191,15 +193,15 @@ impl Rsmime {
191193

192194
#[staticmethod]
193195
#[pyo3(signature = (message, *, raise_on_expired = false))]
194-
fn verify(py_: Python<'_>, message: Vec<u8>, raise_on_expired: bool) -> PyResult<PyObject> {
196+
fn verify(py_: Python<'_>, message: Vec<u8>, raise_on_expired: bool) -> PyResult<Py<PyAny>> {
195197
match _verify(&message, raise_on_expired) {
196198
Ok(data) => Ok(PyBytes::new(py_, &data).into()),
197199
Err(err) => Err(err),
198200
}
199201
}
200202

201203
#[pyo3(signature = (message, *, detached = false))]
202-
fn sign(self_: PyRef<'_, Self>, message: Vec<u8>, detached: bool) -> PyResult<PyObject> {
204+
fn sign(self_: PyRef<'_, Self>, message: Vec<u8>, detached: bool) -> PyResult<Py<PyAny>> {
203205
match _sign(
204206
self_.stack.as_ref(),
205207
self_.cert.as_ref(),

0 commit comments

Comments
 (0)