use super::parser::parse;
use super::types::WireGuardMessage;
use crate::Timestamp;
use crate::event::FlowSide;
use crate::session::DatagramParser;
pub const PARSER_KIND: &str = "wireguard";
pub const WIREGUARD_PORT: u16 = 51820;
#[derive(Debug, Clone, Copy, Default)]
pub struct WireGuardParser;
impl WireGuardParser {
pub fn new() -> Self {
Self
}
}
impl DatagramParser for WireGuardParser {
type Message = WireGuardMessage;
fn parser_kind(&self) -> &'static str {
PARSER_KIND
}
fn parse(
&mut self,
payload: &[u8],
_side: FlowSide,
_ts: Timestamp,
out: &mut Vec<Self::Message>,
) {
if let Some(msg) = parse(payload) {
out.push(msg);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parser_kind_and_port_constants() {
assert_eq!(WireGuardParser.parser_kind(), "wireguard");
assert_eq!(WIREGUARD_PORT, 51820);
}
#[test]
fn unknown_payload_no_event() {
let mut p = WireGuardParser;
let mut out = Vec::new();
p.parse(
b"not a wireguard packet",
FlowSide::Initiator,
Timestamp::default(),
&mut out,
);
assert!(out.is_empty());
}
}