• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /// Sources of length limiting values (e.g. "ipv6 payload length field").
2 #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
3 pub enum LenSource {
4     /// Limiting length was the slice length (we don't know what determined
5     /// that one originally).
6     Slice,
7     /// Length
8     Ipv4HeaderTotalLen,
9     /// Error occurred in the IPv6 layer.
10     Ipv6HeaderPayloadLen,
11     /// Error occurred while decoding an UDP header.
12     UdpHeaderLen,
13     /// Error occurred while decoding a TCP header.
14     TcpHeaderLen,
15     /// Error occurred while decoding a ARP packet.
16     ArpAddrLengths,
17 }
18 
19 #[cfg(test)]
20 mod test {
21     use super::LenSource::*;
22     use alloc::format;
23     use std::{
24         cmp::Ordering,
25         collections::hash_map::DefaultHasher,
26         hash::{Hash, Hasher},
27     };
28 
29     #[test]
debug()30     fn debug() {
31         assert_eq!("Slice", format!("{:?}", Slice));
32     }
33 
34     #[test]
clone_eq_hash_ord()35     fn clone_eq_hash_ord() {
36         let layer = Slice;
37         assert_eq!(layer, layer.clone());
38         let hash_a = {
39             let mut hasher = DefaultHasher::new();
40             layer.hash(&mut hasher);
41             hasher.finish()
42         };
43         let hash_b = {
44             let mut hasher = DefaultHasher::new();
45             layer.clone().hash(&mut hasher);
46             hasher.finish()
47         };
48         assert_eq!(hash_a, hash_b);
49         assert_eq!(Ordering::Equal, layer.cmp(&layer));
50         assert_eq!(Some(Ordering::Equal), layer.partial_cmp(&layer));
51     }
52 }
53