test(rosenpass): adapt gen-ipc-msg-types to fully go through. Explicit test for SHAKE256 still missing

This commit is contained in:
David Niehues
2025-03-14 16:29:11 +01:00
parent d7398d9bcf
commit c9aad280b2
2 changed files with 23 additions and 27 deletions

View File

@@ -33,7 +33,7 @@ fn print_literal(path: &[&str], shake_or_blake: EitherShakeOrBlake) -> Result<()
.map(|chunk| chunk.iter().collect::<String>()) .map(|chunk| chunk.iter().collect::<String>())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
println!("const {var_name} : RawMsgType = RawMsgType::from_le_bytes(hex!(\"{} {} {} {} {} {} {} {}\"));", println!("const {var_name} : RawMsgType = RawMsgType::from_le_bytes(hex!(\"{} {} {} {} {} {} {} {}\"));",
c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
Ok(()) Ok(())
} }
@@ -77,30 +77,25 @@ impl Tree {
/// Helper for generating hash-based message IDs for the IPC API /// Helper for generating hash-based message IDs for the IPC API
fn main() -> Result<()> { fn main() -> Result<()> {
let tree = Tree::Branch(
fn print_IPC_API_info(shake_or_blake: EitherShakeOrBlake, name: String) -> Result<()> { "Rosenpass IPC API".to_owned(),
let tree = Tree::Branch( vec![Tree::Branch(
format!("Rosenpass IPC API {}", name).to_owned(), "Rosenpass Protocol Server".to_owned(),
vec![Tree::Branch( vec![
"Rosenpass Protocol Server".to_owned(), Tree::Leaf("Ping Request".to_owned()),
vec![ Tree::Leaf("Ping Response".to_owned()),
Tree::Leaf("Ping Request".to_owned()), Tree::Leaf("Supply Keypair Request".to_owned()),
Tree::Leaf("Ping Response".to_owned()), Tree::Leaf("Supply Keypair Response".to_owned()),
Tree::Leaf("Supply Keypair Request".to_owned()), Tree::Leaf("Add Listen Socket Request".to_owned()),
Tree::Leaf("Supply Keypair Response".to_owned()), Tree::Leaf("Add Listen Socket Response".to_owned()),
Tree::Leaf("Add Listen Socket Request".to_owned()), Tree::Leaf("Add Psk Broker Request".to_owned()),
Tree::Leaf("Add Listen Socket Response".to_owned()), Tree::Leaf("Add Psk Broker Response".to_owned()),
Tree::Leaf("Add Psk Broker Request".to_owned()), ],
Tree::Leaf("Add Psk Broker Response".to_owned()), )],
], );
)],
);
println!("type RawMsgType = u128;"); println!("type RawMsgType = u128;");
println!(); println!();
tree.gen_code(shake_or_blake) tree.gen_code(EitherShakeOrBlake::Left(SHAKE256Core))?;
} tree.gen_code(EitherShakeOrBlake::Right(Blake2bCore))
print_IPC_API_info(EitherShakeOrBlake::Left(SHAKE256Core), " (SHAKE256)".to_owned())?;
print_IPC_API_info(EitherShakeOrBlake::Right(Blake2bCore), " (Blake2b)".to_owned())
} }

View File

@@ -1,4 +1,4 @@
use std::{borrow::Borrow, process::Command}; use std::{process::Command};
#[test] #[test]
fn test_gen_ipc_msg_types() -> anyhow::Result<()> { fn test_gen_ipc_msg_types() -> anyhow::Result<()> {
@@ -11,5 +11,6 @@ fn test_gen_ipc_msg_types() -> anyhow::Result<()> {
assert!(stdout.contains("type RawMsgType = u128;")); assert!(stdout.contains("type RawMsgType = u128;"));
assert!(stdout.contains("const SUPPLY_KEYPAIR_RESPONSE : RawMsgType = RawMsgType::from_le_bytes(hex!(\"f2dc 49bd e261 5f10 40b7 3c16 ec61 edb9\"));")); assert!(stdout.contains("const SUPPLY_KEYPAIR_RESPONSE : RawMsgType = RawMsgType::from_le_bytes(hex!(\"f2dc 49bd e261 5f10 40b7 3c16 ec61 edb9\"));"));
// TODO: Also test SHAKE256 here
Ok(()) Ok(())
} }