use alloc::string::String;
use crate::ast::Protocol;
use crate::reverse::{ProtocolDissection, be_u32, be_u64, push_hex, push_if, sd};
pub(crate) fn dissect_ikev2(b: &[u8]) -> Option<ProtocolDissection> {
if b.len() < 28 || b[17] != 0x20 {
return None;
}
let (ispi, rspi, np, et, fl, mid) = (
be_u64(b, 0),
be_u64(b, 8),
b[16],
b[18],
b[19],
be_u32(b, 20),
);
let mut t = String::from("ikev2");
match et {
36 => t.push_str(" create_child_sa"),
37 => t.push_str(" informational"),
_ => t.push_str(" sa_init"),
}
push_hex(&mut t, "initiator_spi", ispi, 0x0102_0304_0506_0708, 16);
push_hex(&mut t, "responder_spi", rspi, 0, 16);
push_if(&mut t, "next_payload", np, 0);
push_hex(&mut t, "flags", u64::from(fl), 0x08, 2);
push_if(&mut t, "msgid", mid, 0);
Some(sd(Protocol::Ikev2, t, b[28..].to_vec()))
}