use crate::ast::*;
use alloc::vec::Vec;
pub fn build_ipsec_ah_payload(spec: &AhSpec, payload: &[u8]) -> (Vec<u8>, u8) {
let spi = spec.spi.unwrap_or(0x2000);
let seq = spec.seq.unwrap_or(1);
let next_hdr = spec.next_header.unwrap_or(59);
let icv_bytes: &[u8] = if let Some(icv) = &spec.icv {
icv
} else {
&[0u8; 12]
};
let hdr_len_words = ((12 + icv_bytes.len()).div_ceil(4)).saturating_sub(2) as u8;
let mut ah = Vec::with_capacity(12 + icv_bytes.len() + payload.len());
ah.push(next_hdr);
ah.push(hdr_len_words); ah.extend_from_slice(&[0, 0]); ah.extend_from_slice(&spi.to_be_bytes());
ah.extend_from_slice(&seq.to_be_bytes());
ah.extend_from_slice(icv_bytes);
ah.extend_from_slice(payload);
(ah, 51)
}