From 396f84d4bba808989af805dafe063d2380d153e7 Mon Sep 17 00:00:00 2001 From: glp Date: Wed, 29 Jan 2025 11:43:37 -0800 Subject: [PATCH 1/3] bump pyo3 version in redwood from 0.18.0 to 0.23.4 --- Cargo.lock | 92 ++++++++++++++++++++++--------------------- redwood/Cargo.toml | 6 +-- redwood/src/lib.rs | 11 ++++-- redwood/src/stream.rs | 20 ++++++---- 4 files changed, 68 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e6b176c92..1d775056f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler" @@ -239,7 +239,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", ] [[package]] @@ -354,6 +354,12 @@ version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.3" @@ -498,7 +504,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", ] [[package]] @@ -534,9 +540,9 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.9" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "is-terminal" @@ -649,9 +655,9 @@ checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memoffset" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ "autocfg", ] @@ -727,7 +733,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", ] [[package]] @@ -796,6 +802,12 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "portable-atomic" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -813,15 +825,16 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.18.3" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b1ac5b3731ba34fdaa9785f8d74d17448cd18f30cf19e0c7e7b1fdb5272109" +checksum = "57fe09249128b3173d092de9523eaa75136bf7ba85e0d69eca241c7939c933cc" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -830,9 +843,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.18.3" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cb946f5ac61bb61a5014924910d936ebd2b23b705f7a4a3c40b05c720b079a3" +checksum = "1cd3927b5a78757a0d71aa9dff669f903b1eb64b54142a9bd9f757f8fde65fd7" dependencies = [ "once_cell", "target-lexicon", @@ -840,9 +853,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.18.3" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd4d7c5337821916ea2a1d21d1092e8443cf34879e53a0ac653fbb98f44ff65c" +checksum = "dab6bb2102bd8f991e7749f130a70d05dd557613e39ed2deeee8e9ca0c4d548d" dependencies = [ "libc", "pyo3-build-config", @@ -850,25 +863,27 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.18.3" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d39c55dab3fc5a4b25bbd1ac10a2da452c4aca13bb450f22818a002e29648d" +checksum = "91871864b353fd5ffcb3f91f2f703a22a9797c91b9ab497b1acac7b07ae509c7" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "pyo3-macros-backend" -version = "0.18.3" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97daff08a4c48320587b5224cc98d609e3c27b6d437315bd40b605c98eeb5918" +checksum = "43abc3b80bc20f3facd86cd3c60beed58c3e2aa26213f3cda368de39c60a27e4" dependencies = [ + "heck", "proc-macro2", + "pyo3-build-config", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -1042,7 +1057,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", ] [[package]] @@ -1098,17 +1113,6 @@ dependencies = [ "precomputed-hash", ] -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.87" @@ -1128,14 +1132,14 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", ] [[package]] name = "target-lexicon" -version = "0.12.11" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tempfile" @@ -1178,7 +1182,7 @@ checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", ] [[package]] @@ -1220,9 +1224,9 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unindent" -version = "0.1.11" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "url" @@ -1296,7 +1300,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.87", + "syn", "wasm-bindgen-shared", ] @@ -1318,7 +1322,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1546,7 +1550,7 @@ checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", "synstructure", ] @@ -1567,7 +1571,7 @@ checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", "synstructure", ] @@ -1590,5 +1594,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn", ] diff --git a/redwood/Cargo.toml b/redwood/Cargo.toml index 2c799360e7..8668aad21c 100644 --- a/redwood/Cargo.toml +++ b/redwood/Cargo.toml @@ -10,13 +10,9 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0" -pyo3 = { version = "0.18.0", features = ["extension-module"] } +pyo3 = { version = "0.23.4", features = ["extension-module"] } sequoia-openpgp = { version = "1.21.1", default-features = false, features = ["crypto-openssl", "compression"]} thiserror = "1.0.31" [dev-dependencies] tempfile = "3.3.0" - -[lints.rust] -# can be removed once we upgrade to pyo3 >= 0.23 -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(addr_of)'] } diff --git a/redwood/src/lib.rs b/redwood/src/lib.rs index f1538c63d0..577deb39fa 100644 --- a/redwood/src/lib.rs +++ b/redwood/src/lib.rs @@ -61,14 +61,14 @@ const KEY_CREATION_SECONDS_FROM_EPOCH: u64 = 1368507600; /// A Python module implemented in Rust. #[pymodule] -fn redwood(py: Python, m: &PyModule) -> PyResult<()> { +fn redwood(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(generate_source_key_pair, m)?)?; m.add_function(wrap_pyfunction!(is_valid_public_key, m)?)?; m.add_function(wrap_pyfunction!(is_valid_secret_key, m)?)?; m.add_function(wrap_pyfunction!(encrypt_message, m)?)?; m.add_function(wrap_pyfunction!(encrypt_stream, m)?)?; m.add_function(wrap_pyfunction!(decrypt, m)?)?; - m.add("RedwoodError", py.get_type::())?; + m.add("RedwoodError", m.py().get_type::())?; Ok(()) } @@ -124,7 +124,10 @@ pub fn is_valid_secret_key(input: &str, passphrase: String) -> Result { /// Encrypt a message (text) for the specified recipients. The list of /// recipients is a set of PGP public keys. The encrypted message will /// be written to `destination`. -#[pyfunction] +/// +/// This macro signature addresses a new pyo3 warning about default values... +/// https://github.com/jcmgray/cotengrust/issues/2 +#[pyfunction(signature = (recipients, plaintext, destination, armor=None))] pub fn encrypt_message( recipients: Vec, plaintext: String, @@ -141,7 +144,7 @@ pub fn encrypt_message( #[pyfunction] pub fn encrypt_stream( recipients: Vec, - plaintext: &PyAny, + plaintext: Bound, destination: PathBuf, ) -> Result<()> { let stream = stream::Stream { reader: plaintext }; diff --git a/redwood/src/stream.rs b/redwood/src/stream.rs index 85ddaf6e08..54b931fe80 100644 --- a/redwood/src/stream.rs +++ b/redwood/src/stream.rs @@ -1,21 +1,25 @@ -use pyo3::types::PyBytes; -use pyo3::{intern, PyAny, PyResult}; +//! redwood/stream.rs + + +use pyo3::types::{PyBytes, PyTuple, PyAnyMethods, }; +use pyo3::{Bound, intern, PyAny, PyResult, }; use std::io::{self, ErrorKind, Read, Write}; /// Wrapper to implement the `Read` trait around a Python /// object that contains a `.read()` function. pub(crate) struct Stream<'a> { - pub(crate) reader: &'a PyAny, + pub(crate) reader: Bound<'a, PyAny>, } impl Stream<'_> { /// Read the specified number of bytes out of the object - fn read_bytes(&self, len: usize) -> PyResult<&PyBytes> { - let func = self.reader.getattr(intern!(self.reader.py(), "read"))?; + fn read_bytes(&self, len: usize) -> PyResult> { + let func: Bound<'_, PyAny> = self.reader.getattr(intern!(self.reader.py(), "read"))?; // In Python this is effectively calling `reader.read(len)` - let bytes = func.call1((len,))?; + let args: Bound = PyTuple::new(self.reader.py(), vec![len])?; + let bytes: Bound = func.call1(args)?; let bytes = bytes.downcast::()?; - Ok(bytes) + bytes.extract() } } @@ -27,6 +31,6 @@ impl Read for Stream<'_> { // all of them as "other" for simplicity. io::Error::new(ErrorKind::Other, err.to_string()) })?; - buf.write(bytes.as_bytes()) + buf.write(bytes.as_slice()) } } From 79e15676f0eb15b7b5cc610d66db7f828c1d8e7c Mon Sep 17 00:00:00 2001 From: glp Date: Wed, 29 Jan 2025 11:51:46 -0800 Subject: [PATCH 2/3] bump pyo3 version in redwood from 0.18.0 to 0.23.4 --- redwood/src/stream.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/redwood/src/stream.rs b/redwood/src/stream.rs index 54b931fe80..e2cbe76c5f 100644 --- a/redwood/src/stream.rs +++ b/redwood/src/stream.rs @@ -1,8 +1,7 @@ //! redwood/stream.rs - -use pyo3::types::{PyBytes, PyTuple, PyAnyMethods, }; -use pyo3::{Bound, intern, PyAny, PyResult, }; +use pyo3::types::{PyBytes, PyTuple, PyAnyMethods}; +use pyo3::{Bound, intern, PyAny, PyResult}; use std::io::{self, ErrorKind, Read, Write}; /// Wrapper to implement the `Read` trait around a Python From 705cfdc3b520fcbdafc97f50d2ca92a09c3eb715 Mon Sep 17 00:00:00 2001 From: glp Date: Wed, 5 Feb 2025 15:00:28 -0800 Subject: [PATCH 3/3] cargo fmt --- redwood/src/stream.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/redwood/src/stream.rs b/redwood/src/stream.rs index e2cbe76c5f..ba872bf4c8 100644 --- a/redwood/src/stream.rs +++ b/redwood/src/stream.rs @@ -1,7 +1,7 @@ //! redwood/stream.rs -use pyo3::types::{PyBytes, PyTuple, PyAnyMethods}; -use pyo3::{Bound, intern, PyAny, PyResult}; +use pyo3::types::{PyAnyMethods, PyBytes, PyTuple}; +use pyo3::{intern, Bound, PyAny, PyResult}; use std::io::{self, ErrorKind, Read, Write}; /// Wrapper to implement the `Read` trait around a Python @@ -13,7 +13,8 @@ pub(crate) struct Stream<'a> { impl Stream<'_> { /// Read the specified number of bytes out of the object fn read_bytes(&self, len: usize) -> PyResult> { - let func: Bound<'_, PyAny> = self.reader.getattr(intern!(self.reader.py(), "read"))?; + let func: Bound<'_, PyAny> = + self.reader.getattr(intern!(self.reader.py(), "read"))?; // In Python this is effectively calling `reader.read(len)` let args: Bound = PyTuple::new(self.reader.py(), vec![len])?; let bytes: Bound = func.call1(args)?;