Skip to content

Commit

Permalink
do not use impl AsRef in convert_to_pybytes
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMaul committed Sep 13, 2024
1 parent 1977bde commit dc14d6d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Account {
Session {
inner: result.session,
},
convert_to_pybytes(result.plaintext),
convert_to_pybytes(result.plaintext.as_slice()),
))
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ fn my_module(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}

pub(crate) fn convert_to_pybytes(bytes: impl AsRef<[u8]>) -> Py<PyBytes> {
Python::with_gil(|py| PyBytes::new_bound(py, bytes.as_ref()).into())
pub(crate) fn convert_to_pybytes(bytes: &[u8]) -> Py<PyBytes> {
Python::with_gil(|py| PyBytes::new_bound(py, bytes).into())
}
4 changes: 3 additions & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ impl Session {
}

fn decrypt(&mut self, message: &AnyOlmMessage) -> Result<Py<PyBytes>, SessionError> {
Ok(convert_to_pybytes(self.inner.decrypt(&message.inner)?))
Ok(convert_to_pybytes(
self.inner.decrypt(&message.inner)?.as_slice(),
))
}
}
2 changes: 1 addition & 1 deletion src/types/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl AnyOlmMessage {

pub fn to_parts(&self) -> (usize, Py<PyBytes>) {
let (message_type, ciphertext) = self.inner.clone().to_parts();
(message_type, convert_to_pybytes(ciphertext))
(message_type, convert_to_pybytes(ciphertext.as_slice()))
}
}

Expand Down

0 comments on commit dc14d6d

Please sign in to comment.