From b0951f3b9f3da59136e91c3abda00154512fe893 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 13:26:17 -0400 Subject: [PATCH] build(deps): bump the cargo group with 1 update (#64) * build(deps): bump the cargo group with 1 update Bumps the cargo group with 1 update: [pyo3](https://github.com/pyo3/pyo3). Updates `pyo3` from 0.20.3 to 0.21.0 - [Release notes](https://github.com/pyo3/pyo3/releases) - [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md) - [Commits](https://github.com/pyo3/pyo3/compare/v0.20.3...v0.21.0) --- updated-dependencies: - dependency-name: pyo3 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: cargo ... Signed-off-by: dependabot[bot] * pyo3 fixes Signed-off-by: William Woodruff --------- Signed-off-by: dependabot[bot] Signed-off-by: William Woodruff Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: William Woodruff --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- pyproject.toml | 2 +- src/lib.rs | 42 +++++++++++++++++++++--------------------- src/passphrase.rs | 16 ++++++++++------ src/ssh.rs | 8 ++++---- src/x25519.rs | 10 +++++----- 7 files changed, 52 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79dafe8..9ff7704 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -858,9 +858,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.20.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233" +checksum = "a02a88a17e74cadbc8ce77855e1d6c8ad0ab82901a4a9b5046bd01c1c0bd95cd" dependencies = [ "cfg-if", "indoc", @@ -876,9 +876,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.20.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7" +checksum = "a5eb0b6ecba38961f6f4bd6cd5906dfab3cd426ff37b2eed5771006aa31656f1" dependencies = [ "once_cell", "target-lexicon", @@ -886,9 +886,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.20.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa" +checksum = "ba8a6e48a29b5d22e4fdaf132d8ba8d3203ee9f06362d48f244346902a594ec3" dependencies = [ "libc", "pyo3-build-config", @@ -896,9 +896,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.20.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158" +checksum = "4e80493c5965f94a747d0782a607b2328a4eea5391327b152b00e2f3b001cede" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -908,9 +908,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.20.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185" +checksum = "fcd7d86f42004025200e12a6a8119bd878329e6fddef8178eaafa4e4b5906c5b" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 25413c7..52c6c53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ crate-type = ["cdylib"] [dependencies] age-core = "0.10" age = { version = "0.10", features = ["ssh"] } -pyo3 = { version = "0.20", features = [ +pyo3 = { version = "0.21", features = [ "extension-module", "abi3", "abi3-py38", diff --git a/pyproject.toml b/pyproject.toml index d8f713d..dcaa1d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.14,<0.15"] +requires = ["maturin>=1.0,<2.0"] build-backend = "maturin" [project] diff --git a/src/lib.rs b/src/lib.rs index 35860bc..216bca8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ use pyo3::{ exceptions::{PyException, PyTypeError}, prelude::*, py_run, - types::{PyBytes, PyString}, + types::PyBytes, }; mod passphrase; @@ -135,7 +135,7 @@ fn encrypt<'p>( py: Python<'p>, plaintext: &[u8], recipients: Vec>, -) -> PyResult<&'p PyBytes> { +) -> PyResult> { // This turns each `dyn PyrageRecipient` into a `dyn Recipient`, which // is what the underlying `age` API expects. let recipients = recipients.into_iter().map(|pr| pr.as_recipient()).collect(); @@ -154,21 +154,21 @@ fn encrypt<'p>( .map_err(|e| EncryptError::new_err(e.to_string()))?; // TODO: Avoid this copy. Maybe PyBytes::new_with? - Ok(PyBytes::new(py, &encrypted)) + Ok(PyBytes::new_bound(py, &encrypted)) } #[pyfunction] fn encrypt_file( - infile: &PyString, - outfile: &PyString, + infile: String, + outfile: String, recipients: Vec>, ) -> PyResult<()> { // This turns each `dyn PyrageRecipient` into a `dyn Recipient`, which // is what the underlying `age` API expects. let recipients = recipients.into_iter().map(|pr| pr.as_recipient()).collect(); - let reader = File::open(infile.to_str()?)?; - let writer = File::create(outfile.to_str()?)?; + let reader = File::open(infile)?; + let writer = File::create(outfile)?; let mut reader = std::io::BufReader::new(reader); let mut writer = std::io::BufWriter::new(writer); @@ -195,7 +195,7 @@ fn decrypt<'p>( py: Python<'p>, ciphertext: &[u8], identities: Vec>, -) -> PyResult<&'p PyBytes> { +) -> PyResult> { let identities = identities.iter().map(|pi| pi.as_ref().as_identity()); let decryptor = @@ -217,19 +217,19 @@ fn decrypt<'p>( .map_err(|e| DecryptError::new_err(e.to_string()))?; // TODO: Avoid this copy. Maybe PyBytes::new_with? - Ok(PyBytes::new(py, &decrypted)) + Ok(PyBytes::new_bound(py, &decrypted)) } #[pyfunction] fn decrypt_file( - infile: &PyString, - outfile: &PyString, + infile: String, + outfile: String, identities: Vec>, ) -> PyResult<()> { let identities = identities.iter().map(|pi| pi.as_ref().as_identity()); - let reader = File::open(infile.to_str()?)?; - let writer = File::create(outfile.to_str()?)?; + let reader = File::open(infile)?; + let writer = File::create(outfile)?; let reader = std::io::BufReader::new(reader); let mut writer = std::io::BufWriter::new(writer); @@ -255,7 +255,7 @@ fn decrypt_file( } #[pymodule] -fn pyrage(py: Python, m: &PyModule) -> PyResult<()> { +fn pyrage(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { // HACK(ww): pyO3 modules are not packages, so we need this nasty // `py_run!` hack to support `from pyrage import ...` and similar // import patterns. @@ -265,11 +265,11 @@ fn pyrage(py: Python, m: &PyModule) -> PyResult<()> { x25519, "import sys; sys.modules['pyrage.x25519'] = x25519" ); - m.add_submodule(x25519)?; + m.add_submodule(&x25519)?; let ssh = ssh::module(py)?; py_run!(py, ssh, "import sys; sys.modules['pyrage.ssh'] = ssh"); - m.add_submodule(ssh)?; + m.add_submodule(&ssh)?; let passphrase = passphrase::module(py)?; py_run!( @@ -277,15 +277,15 @@ fn pyrage(py: Python, m: &PyModule) -> PyResult<()> { passphrase, "import sys; sys.modules['pyrage.passphrase'] = passphrase" ); - m.add_submodule(passphrase)?; + m.add_submodule(&passphrase)?; - m.add("IdentityError", py.get_type::())?; - m.add("RecipientError", py.get_type::())?; + m.add("IdentityError", py.get_type_bound::())?; + m.add("RecipientError", py.get_type_bound::())?; - m.add("EncryptError", py.get_type::())?; + m.add("EncryptError", py.get_type_bound::())?; m.add_wrapped(wrap_pyfunction!(encrypt))?; m.add_wrapped(wrap_pyfunction!(encrypt_file))?; - m.add("DecryptError", py.get_type::())?; + m.add("DecryptError", py.get_type_bound::())?; m.add_wrapped(wrap_pyfunction!(decrypt))?; m.add_wrapped(wrap_pyfunction!(decrypt_file))?; diff --git a/src/passphrase.rs b/src/passphrase.rs index 49bfd71..367a21a 100644 --- a/src/passphrase.rs +++ b/src/passphrase.rs @@ -6,7 +6,7 @@ use pyo3::{prelude::*, types::PyBytes}; use crate::{DecryptError, EncryptError}; #[pyfunction] -fn encrypt<'p>(py: Python<'p>, plaintext: &[u8], passphrase: &str) -> PyResult<&'p PyBytes> { +fn encrypt<'p>(py: Python<'p>, plaintext: &[u8], passphrase: &str) -> PyResult> { let encryptor = Encryptor::with_user_passphrase(Secret::new(passphrase.into())); let mut encrypted = vec![]; let mut writer = encryptor @@ -19,11 +19,15 @@ fn encrypt<'p>(py: Python<'p>, plaintext: &[u8], passphrase: &str) -> PyResult<& .finish() .map_err(|e| EncryptError::new_err(e.to_string()))?; - Ok(PyBytes::new(py, &encrypted)) + Ok(PyBytes::new_bound(py, &encrypted)) } #[pyfunction] -fn decrypt<'p>(py: Python<'p>, ciphertext: &[u8], passphrase: &str) -> PyResult<&'p PyBytes> { +fn decrypt<'p>( + py: Python<'p>, + ciphertext: &[u8], + passphrase: &str, +) -> PyResult> { let decryptor = match Decryptor::new(ciphertext).map_err(|e| DecryptError::new_err(e.to_string()))? { Decryptor::Passphrase(d) => d, @@ -41,11 +45,11 @@ fn decrypt<'p>(py: Python<'p>, ciphertext: &[u8], passphrase: &str) -> PyResult< .read_to_end(&mut decrypted) .map_err(|e| DecryptError::new_err(e.to_string()))?; - Ok(PyBytes::new(py, &decrypted)) + Ok(PyBytes::new_bound(py, &decrypted)) } -pub(crate) fn module(py: Python) -> PyResult<&PyModule> { - let module = PyModule::new(py, "passphrase")?; +pub(crate) fn module(py: Python) -> PyResult> { + let module = PyModule::new_bound(py, "passphrase")?; module.add_wrapped(wrap_pyfunction!(encrypt))?; module.add_wrapped(wrap_pyfunction!(decrypt))?; diff --git a/src/ssh.rs b/src/ssh.rs index 18acbf8..fc1284f 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -11,7 +11,7 @@ pub(crate) struct Recipient(pub(crate) age::ssh::Recipient); #[pymethods] impl Recipient { #[classmethod] - fn from_str(_cls: &PyType, v: &str) -> PyResult { + fn from_str(_cls: &Bound<'_, PyType>, v: &str) -> PyResult { let recipient = age::ssh::Recipient::from_str(v) .map_err(|e| RecipientError::new_err(format!("invalid public key: {:?}", e)))?; @@ -26,7 +26,7 @@ pub(crate) struct Identity(pub(crate) age::ssh::Identity); #[pymethods] impl Identity { #[classmethod] - fn from_buffer(_cls: &PyType, buf: &[u8]) -> PyResult { + fn from_buffer(_cls: &Bound<'_, PyType>, buf: &[u8]) -> PyResult { let identity = age::ssh::Identity::from_buffer(buf, None) .map_err(|e| IdentityError::new_err(e.to_string()))?; @@ -43,8 +43,8 @@ impl Identity { } } -pub(crate) fn module(py: Python) -> PyResult<&PyModule> { - let module = PyModule::new(py, "ssh")?; +pub(crate) fn module(py: Python) -> PyResult> { + let module = PyModule::new_bound(py, "ssh")?; module.add_class::()?; module.add_class::()?; diff --git a/src/x25519.rs b/src/x25519.rs index 7c7025d..530577f 100644 --- a/src/x25519.rs +++ b/src/x25519.rs @@ -12,7 +12,7 @@ pub(crate) struct Recipient(pub(crate) age::x25519::Recipient); #[pymethods] impl Recipient { #[classmethod] - fn from_str(_cls: &PyType, v: &str) -> PyResult { + fn from_str(_cls: &Bound<'_, PyType>, v: &str) -> PyResult { age::x25519::Recipient::from_str(v) .map(Self) .map_err(RecipientError::new_err) @@ -30,12 +30,12 @@ pub(crate) struct Identity(pub(crate) age::x25519::Identity); #[pymethods] impl Identity { #[classmethod] - fn generate(_cls: &PyType) -> Self { + fn generate(_cls: &Bound<'_, PyType>) -> Self { Self(age::x25519::Identity::generate()) } #[classmethod] - fn from_str(_cls: &PyType, v: &str) -> PyResult { + fn from_str(_cls: &Bound<'_, PyType>, v: &str) -> PyResult { let identity = age::x25519::Identity::from_str(v) .map_err(|e| IdentityError::new_err(e.to_string()))?; @@ -51,8 +51,8 @@ impl Identity { } } -pub(crate) fn module(py: Python) -> PyResult<&PyModule> { - let module = PyModule::new(py, "x25519")?; +pub(crate) fn module(py: Python) -> PyResult> { + let module = PyModule::new_bound(py, "x25519")?; module.add_class::()?; module.add_class::()?;