Skip to content

Commit

Permalink
build(deps): bump the cargo group with 1 update (#64)
Browse files Browse the repository at this point in the history
* 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](PyO3/pyo3@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] <[email protected]>

* pyo3 fixes

Signed-off-by: William Woodruff <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: William Woodruff <[email protected]>
  • Loading branch information
dependabot[bot] and woodruffw authored Apr 1, 2024
1 parent 77162b6 commit b0951f3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 48 deletions.
20 changes: 10 additions & 10 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["maturin>=0.14,<0.15"]
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[project]
Expand Down
42 changes: 21 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use pyo3::{
exceptions::{PyException, PyTypeError},
prelude::*,
py_run,
types::{PyBytes, PyString},
types::PyBytes,
};

mod passphrase;
Expand Down Expand Up @@ -135,7 +135,7 @@ fn encrypt<'p>(
py: Python<'p>,
plaintext: &[u8],
recipients: Vec<Box<dyn PyrageRecipient>>,
) -> PyResult<&'p PyBytes> {
) -> PyResult<Bound<'p, PyBytes>> {
// 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();
Expand All @@ -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<Box<dyn PyrageRecipient>>,
) -> 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);
Expand All @@ -195,7 +195,7 @@ fn decrypt<'p>(
py: Python<'p>,
ciphertext: &[u8],
identities: Vec<Box<dyn PyrageIdentity>>,
) -> PyResult<&'p PyBytes> {
) -> PyResult<Bound<'p, PyBytes>> {
let identities = identities.iter().map(|pi| pi.as_ref().as_identity());

let decryptor =
Expand All @@ -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<Box<dyn PyrageIdentity>>,
) -> 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);
Expand All @@ -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.
Expand All @@ -265,27 +265,27 @@ 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!(
py,
passphrase,
"import sys; sys.modules['pyrage.passphrase'] = passphrase"
);
m.add_submodule(passphrase)?;
m.add_submodule(&passphrase)?;

m.add("IdentityError", py.get_type::<IdentityError>())?;
m.add("RecipientError", py.get_type::<RecipientError>())?;
m.add("IdentityError", py.get_type_bound::<IdentityError>())?;
m.add("RecipientError", py.get_type_bound::<RecipientError>())?;

m.add("EncryptError", py.get_type::<EncryptError>())?;
m.add("EncryptError", py.get_type_bound::<EncryptError>())?;
m.add_wrapped(wrap_pyfunction!(encrypt))?;
m.add_wrapped(wrap_pyfunction!(encrypt_file))?;
m.add("DecryptError", py.get_type::<DecryptError>())?;
m.add("DecryptError", py.get_type_bound::<DecryptError>())?;
m.add_wrapped(wrap_pyfunction!(decrypt))?;
m.add_wrapped(wrap_pyfunction!(decrypt_file))?;

Expand Down
16 changes: 10 additions & 6 deletions src/passphrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bound<'p, PyBytes>> {
let encryptor = Encryptor::with_user_passphrase(Secret::new(passphrase.into()));
let mut encrypted = vec![];
let mut writer = encryptor
Expand All @@ -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<Bound<'p, PyBytes>> {
let decryptor =
match Decryptor::new(ciphertext).map_err(|e| DecryptError::new_err(e.to_string()))? {
Decryptor::Passphrase(d) => d,
Expand All @@ -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<Bound<'_, PyModule>> {
let module = PyModule::new_bound(py, "passphrase")?;

module.add_wrapped(wrap_pyfunction!(encrypt))?;
module.add_wrapped(wrap_pyfunction!(decrypt))?;
Expand Down
8 changes: 4 additions & 4 deletions src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
fn from_str(_cls: &Bound<'_, PyType>, v: &str) -> PyResult<Self> {
let recipient = age::ssh::Recipient::from_str(v)
.map_err(|e| RecipientError::new_err(format!("invalid public key: {:?}", e)))?;

Expand All @@ -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<Self> {
fn from_buffer(_cls: &Bound<'_, PyType>, buf: &[u8]) -> PyResult<Self> {
let identity = age::ssh::Identity::from_buffer(buf, None)
.map_err(|e| IdentityError::new_err(e.to_string()))?;

Expand All @@ -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<Bound<'_, PyModule>> {
let module = PyModule::new_bound(py, "ssh")?;

module.add_class::<Recipient>()?;
module.add_class::<Identity>()?;
Expand Down
10 changes: 5 additions & 5 deletions src/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
fn from_str(_cls: &Bound<'_, PyType>, v: &str) -> PyResult<Self> {
age::x25519::Recipient::from_str(v)
.map(Self)
.map_err(RecipientError::new_err)
Expand All @@ -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<Self> {
fn from_str(_cls: &Bound<'_, PyType>, v: &str) -> PyResult<Self> {
let identity = age::x25519::Identity::from_str(v)
.map_err(|e| IdentityError::new_err(e.to_string()))?;

Expand All @@ -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<Bound<'_, PyModule>> {
let module = PyModule::new_bound(py, "x25519")?;

module.add_class::<Recipient>()?;
module.add_class::<Identity>()?;
Expand Down

0 comments on commit b0951f3

Please sign in to comment.