Skip to content

Commit

Permalink
change 'verify_and_open' signature to be more complementary to Store
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Schoolderman <[email protected]>
  • Loading branch information
tweedegolf-marc committed Jul 26, 2024
1 parent 43e5e2d commit 78547df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 2 additions & 4 deletions examples/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,8 @@ async fn run() -> Result<(), Error> {
None
};

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

info!(
"{vid} is verified and added to the database {}",
Expand Down
13 changes: 6 additions & 7 deletions tsp/src/async_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,15 @@ impl AsyncStore {
}

/// Process the payload from a 'PendingMessage' by resolving the unknown vid and retrying
pub async fn verify_and_open<'a, T: AsRef<[u8]>>(
/// This takes a Vec as a payload; for a borrowing version the `as_inner()` version can be used; usually after
/// unpacking a TSP message you can't or need to do anything with it anyway.
pub async fn verify_and_open(
&mut self,
vid: &str,
payload: &'a mut [u8],
) -> Result<ReceivedTspMessage<T>, Error>
where
&'a [u8]: Into<T>,
{
mut payload: Vec<u8>,
) -> Result<ReceivedTspMessage, Error> {
self.verify_vid(vid).await?;

Ok(self.inner.open_message(payload)?.map(|x| x.into()))
Ok(self.inner.open_message(&mut payload)?.into_owned())
}
}

0 comments on commit 78547df

Please sign in to comment.