]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
frames (rust): method to create StreamSlice from slice
authorJason Ish <jason.ish@oisf.net>
Tue, 8 Feb 2022 21:45:05 +0000 (15:45 -0600)
committerVictor Julien <vjulien@oisf.net>
Sat, 30 Apr 2022 06:01:49 +0000 (08:01 +0200)
Useful in unit test for function that require a StreamSlice.

rust/src/applayer.rs

index e0df43298f6c5d64813bff430a725e70eff164d9..a7193472e06636bb84ddb1bb2d3fde7ede739ded 100644 (file)
@@ -39,6 +39,17 @@ pub struct StreamSlice {
 }
 
 impl StreamSlice {
+
+    /// Create a StreamSlice from a Rust slice. Useful in unit tests.
+    pub fn from_slice(slice: &[u8], flags: u8, offset: u64) -> Self {
+        Self {
+            input: slice.as_ptr() as *const u8,
+            input_len: slice.len() as u32,
+            flags,
+            offset
+        }
+    }
+
     pub fn is_gap(&self) -> bool {
         self.input.is_null() && self.input_len > 0
     }