diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
commit | a0aa2307322cd47bbf416810ac0292925e03be87 (patch) | |
tree | 37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/sawp/src/probe.rs | |
parent | Initial commit. (diff) | |
download | suricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip |
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rust/vendor/sawp/src/probe.rs')
-rw-r--r-- | rust/vendor/sawp/src/probe.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/rust/vendor/sawp/src/probe.rs b/rust/vendor/sawp/src/probe.rs new file mode 100644 index 0000000..3aa976d --- /dev/null +++ b/rust/vendor/sawp/src/probe.rs @@ -0,0 +1,31 @@ +use crate::error::{Error, ErrorKind}; +use crate::parser::{Direction, Parse}; +use crate::protocol::Protocol; + +/// Result of probing the underlying bytes. +#[derive(Debug, PartialEq)] +pub enum Status { + /// Data matches this protocol + Recognized, + /// Data does not match this protocol + Unrecognized, + /// More data is needed to make a decision + Incomplete, +} + +pub trait Probe<'a>: Protocol<'a> + Parse<'a> { + /// Probes the input to recognize if the underlying bytes likely match this + /// protocol. + /// + /// Returns a probe status. Probe again once more data is available when the + /// status is `Status::Incomplete`. + fn probe(&self, input: &'a [u8], direction: Direction) -> Status { + match self.parse(input, direction) { + Ok((_, _)) => Status::Recognized, + Err(Error { + kind: ErrorKind::Incomplete(_), + }) => Status::Incomplete, + Err(_) => Status::Unrecognized, + } + } +} |