use alloc::string::String;
use core::fmt::Write as _;
use crate::ast::Protocol;
use crate::reverse::{ProtocolDissection, be_u32, bytes_to_hex_lower, push_hex, push_if, sd};
pub(crate) fn dissect_ah(b: &[u8]) -> ProtocolDissection {
let ah_len = ((b.get(1).copied().unwrap_or(4) as usize) + 2) * 4;
if b.len() < 12 || b.len() < ah_len {
return sd(Protocol::Ah, String::from("ah"), b.to_vec());
}
let mut t = String::from("ah");
push_if(&mut t, "next_header", b[0], 59);
push_hex(&mut t, "spi", u64::from(be_u32(b, 4)), 0x2000, 1);
push_if(&mut t, "seq", be_u32(b, 8), 1);
let icv = &b[12..ah_len];
if icv != [0u8; 12] {
let _ = write!(t, " icv \"{}\"", bytes_to_hex_lower(icv));
}
sd(Protocol::Ah, t, b[ah_len..].to_vec())
}