Skip to content

Commit

Permalink
make payload a Vec<u8>; easier for external APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Folkert <[email protected]>
  • Loading branch information
folkertdev committed Jun 4, 2024
1 parent 0820eb1 commit 56773d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions examples/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,10 @@ async fn run() -> Result<(), Error> {
None
};

if let Some((unknown_vid, payload)) = handle_message(message) {
let message = vid_database.verify_and_open(&unknown_vid, payload).await?;
if let Some((unknown_vid, mut payload)) = handle_message(message) {
let message = vid_database
.verify_and_open(&unknown_vid, &mut payload)
.await?;

write_database(&args.database, &vid_database, aliases.clone()).await?;

Expand Down
6 changes: 3 additions & 3 deletions tsp/src/async_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl AsyncStore {
Err(Error::UnverifiedSource(unknown_vid)) => {
Ok(ReceivedTspMessage::PendingMessage {
unknown_vid,
payload: m,
payload: m.to_vec(),
})
}
maybe_message => maybe_message,
Expand Down Expand Up @@ -379,10 +379,10 @@ impl AsyncStore {
pub async fn verify_and_open(
&mut self,
vid: &str,
mut payload: tokio_util::bytes::BytesMut,
payload: &mut [u8],
) -> Result<ReceivedTspMessage, Error> {
self.verify_vid(vid).await?;

self.inner.open_message(&mut payload)
self.inner.open_message(payload)
}
}
2 changes: 1 addition & 1 deletion tsp/src/definitions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum ReceivedTspMessage {
#[cfg(feature = "async")]
PendingMessage {
unknown_vid: String,
payload: tokio_util::bytes::BytesMut,
payload: Vec<u8>,
},
}

Expand Down
7 changes: 5 additions & 2 deletions tsp/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ async fn attack_failures() {
if let Ok(msg) = bobs_messages.next().await.unwrap() {
let crate::ReceivedTspMessage::PendingMessage {
unknown_vid,
payload,
mut payload,
} = msg
else {
panic!("a corrupted message was decoded correctly!");
Expand All @@ -474,7 +474,10 @@ async fn attack_failures() {
// confirm that opening the pending message also fails
// (We cannot test this exhaustively -- but because the cryptographic material for this
// message does not belong to the corrupted vid, it should reliably always fail)
assert!(bob_db.verify_and_open(&unknown_vid, payload).await.is_err());
assert!(bob_db
.verify_and_open(&unknown_vid, &mut payload)
.await
.is_err());
};

if stop {
Expand Down

0 comments on commit 56773d1

Please sign in to comment.