Skip to content

Commit

Permalink
Add assertions for interchange size
Browse files Browse the repository at this point in the history
This patch adds assertions on the size of the Request, Reply and
TrussedInterchange types so that we don’t accidentally increase it.
  • Loading branch information
robin-nitrokey committed Feb 14, 2023
1 parent 6a82b78 commit c62c1c8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,36 @@ pub struct ServiceEndpoint<I: 'static, C> {
}

// pub type ClientEndpoint = Requester<TrussedInterchange>;

#[cfg(test)]
mod tests {
use super::TrussedInterchange;
use crate::api::{Reply, Request};
use core::mem;

// The following checks are used to ensure that we don’t accidentally increase the interchange
// size. Bumping the size is not a breaking change but should only be done if really
// necessary.

const MAX_SIZE: usize = 2416;

fn assert_size<T>() {
let size = mem::size_of::<T>();
assert!(size <= MAX_SIZE, "{size}");
}

#[test]
fn test_request_size() {
assert_size::<Request>();
}

#[test]
fn test_reply_size() {
assert_size::<Reply>();
}

#[test]
fn test_interchange_size() {
assert_size::<TrussedInterchange>();
}
}

0 comments on commit c62c1c8

Please sign in to comment.