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>())
.collect::<Vec<_>>();
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(())
}
@@ -77,30 +77,25 @@ impl Tree {
/// Helper for generating hash-based message IDs for the IPC API
fn main() -> Result<()> {
fn print_IPC_API_info(shake_or_blake: EitherShakeOrBlake, name: String) -> Result<()> {
let tree = Tree::Branch(
format!("Rosenpass IPC API {}", name).to_owned(),
vec![Tree::Branch(
"Rosenpass Protocol Server".to_owned(),
vec![
Tree::Leaf("Ping Request".to_owned()),
Tree::Leaf("Ping Response".to_owned()),
Tree::Leaf("Supply Keypair Request".to_owned()),
Tree::Leaf("Supply Keypair Response".to_owned()),
Tree::Leaf("Add Listen Socket Request".to_owned()),
Tree::Leaf("Add Listen Socket Response".to_owned()),
Tree::Leaf("Add Psk Broker Request".to_owned()),
Tree::Leaf("Add Psk Broker Response".to_owned()),
],
)],
);
let tree = Tree::Branch(
"Rosenpass IPC API".to_owned(),
vec![Tree::Branch(
"Rosenpass Protocol Server".to_owned(),
vec![
Tree::Leaf("Ping Request".to_owned()),
Tree::Leaf("Ping Response".to_owned()),
Tree::Leaf("Supply Keypair Request".to_owned()),
Tree::Leaf("Supply Keypair Response".to_owned()),
Tree::Leaf("Add Listen Socket Request".to_owned()),
Tree::Leaf("Add Listen Socket Response".to_owned()),
Tree::Leaf("Add Psk Broker Request".to_owned()),
Tree::Leaf("Add Psk Broker Response".to_owned()),
],
)],
);
println!("type RawMsgType = u128;");
println!();
tree.gen_code(shake_or_blake)
}
print_IPC_API_info(EitherShakeOrBlake::Left(SHAKE256Core), " (SHAKE256)".to_owned())?;
print_IPC_API_info(EitherShakeOrBlake::Right(Blake2bCore), " (Blake2b)".to_owned())
println!("type RawMsgType = u128;");
println!();
tree.gen_code(EitherShakeOrBlake::Left(SHAKE256Core))?;
tree.gen_code(EitherShakeOrBlake::Right(Blake2bCore))
}

View File

@@ -1,4 +1,4 @@
use std::{borrow::Borrow, process::Command};
use std::{process::Command};
#[test]
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("const SUPPLY_KEYPAIR_RESPONSE : RawMsgType = RawMsgType::from_le_bytes(hex!(\"f2dc 49bd e261 5f10 40b7 3c16 ec61 edb9\"));"));
// TODO: Also test SHAKE256 here
Ok(())
}