Skip to content

Commit

Permalink
Merge pull request #257 from chrysn-pull-requests/py-return-no-vec-u8
Browse files Browse the repository at this point in the history
python: Don't return Vec<u8>
  • Loading branch information
geonnave authored May 3, 2024
2 parents ed3c5ea + 9baa466 commit 643ee3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lakers-python/src/initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ impl PyEdhocInitiator {
}
}

pub fn parse_message_2(
pub fn parse_message_2<'a>(
&mut self,
py: Python<'a>,
message_2: Vec<u8>,
) -> PyResult<(u8, Vec<u8>, Option<EADItem>)> {
) -> PyResult<(u8, &'a PyBytes, Option<EADItem>)> {
let message_2 = EdhocMessageBuffer::new_from_slice(message_2.as_slice())?;

match i_parse_message_2(&self.wait_m2, &mut default_crypto(), &message_2) {
Ok((state, c_r, id_cred_r, ead_2)) => {
self.processing_m2 = state;
let id_cred_r = if id_cred_r.reference_only() {
Vec::from([id_cred_r.kid])
PyBytes::new(py, &[id_cred_r.kid])
} else {
Vec::from(id_cred_r.value.as_slice())
PyBytes::new(py, id_cred_r.value.as_slice())
};
Ok((c_r, id_cred_r, ead_2))
}
Expand Down
10 changes: 7 additions & 3 deletions lakers-python/src/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ impl PyEdhocResponder {
}
}

pub fn parse_message_3(&mut self, message_3: Vec<u8>) -> PyResult<(Vec<u8>, Option<EADItem>)> {
pub fn parse_message_3<'a>(
&mut self,
py: Python<'a>,
message_3: Vec<u8>,
) -> PyResult<(&'a PyBytes, Option<EADItem>)> {
let message_3 = EdhocMessageBuffer::new_from_slice(message_3.as_slice())?;
match r_parse_message_3(&mut self.wait_m3, &mut default_crypto(), &message_3) {
Ok((state, id_cred_i, ead_3)) => {
self.processing_m3 = state;
let id_cred_i = if id_cred_i.reference_only() {
Vec::from([id_cred_i.kid])
PyBytes::new(py, &[id_cred_i.kid])
} else {
Vec::from(id_cred_i.value.as_slice())
PyBytes::new(py, id_cred_i.value.as_slice())
};
Ok((id_cred_i, ead_3))
}
Expand Down

0 comments on commit 643ee3c

Please sign in to comment.