Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions etherparse/proptest-regressions/net/ipv4_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc fc12b54abbe610c4344c9f792ab4c501830e658c699e926cebafc50e5c156975 # shrinks to source_ip = [0, 0, 0, 0], dest_ip = [0, 0, 0, 0], ttl = 0, ok_payload_len = 0, err_payload_len = 65516
2 changes: 1 addition & 1 deletion etherparse/src/compositions_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ impl<'a> ComponentTest<'a> {
proptest! {
///Test that all known packet compositions are parsed correctly.
#[test]
// #[cfg_attr(miri, ignore)] // vec allocation reduces miri runspeed too much
// #[cfg_attr(miri, ignore)] // vec allocation reduces miri run-speed too much
fn test_compositions(ref eth in ethernet_2_unknown(),
ref vlan0 in vlan_single_unknown(),
ref vlan1 in vlan_single_unknown(),
Expand Down
67 changes: 67 additions & 0 deletions etherparse/src/err/ip/ip_dscp_unknown_value_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use core::{cmp::Eq, cmp::PartialEq, fmt::Debug, hash::Hash};

/// Error if an unknown value is passed to [`crate::IpDscpKnown::try_from_ip_dscp`].
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct IpDscpUnknownValueError {
/// Unknown DSCP value that caused the error.
pub value: u8,
}

impl core::fmt::Display for IpDscpUnknownValueError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Error DSCP value '{}' is not known.", self.value)
}
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for IpDscpUnknownValueError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}

#[cfg(test)]
mod test {
use super::*;
use std::{collections::hash_map::DefaultHasher, error::Error, format, hash::Hasher};

#[test]
fn fmt() {
assert_eq!(
format!("{}", IpDscpUnknownValueError { value: 3 }),
"Error DSCP value '3' is not known."
);
}

#[test]
fn dbg() {
assert_eq!(
format!("{:?}", IpDscpUnknownValueError { value: 3 }),
format!("IpDscpUnknownValueError {{ value: {} }}", 3)
);
}

#[test]
fn clone_eq_hash() {
let err = IpDscpUnknownValueError { value: 3 };
assert_eq!(err, err.clone());
let hash_a = {
let mut hasher = DefaultHasher::new();
err.hash(&mut hasher);
hasher.finish()
};
let hash_b = {
let mut hasher = DefaultHasher::new();
err.clone().hash(&mut hasher);
hasher.finish()
};
assert_eq!(hash_a, hash_b);
}

#[cfg(feature = "std")]
#[test]
fn source() {
assert!(IpDscpUnknownValueError { value: 3 }.source().is_none());
}
}
3 changes: 3 additions & 0 deletions etherparse/src/err/ip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ mod headers_write_error;
#[cfg(feature = "std")]
pub use headers_write_error::*;

pub mod ip_dscp_unknown_value_error;
pub use ip_dscp_unknown_value_error::*;

mod lax_header_slice_error;
pub use lax_header_slice_error::*;

Expand Down
24 changes: 12 additions & 12 deletions etherparse/src/err/value_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ pub enum ValueType {
VlanId,
/// VLAN PCP (Priority Code Point) field in a [`crate::SingleVlanHeader`].
VlanPcp,
/// MACsec association number (present in the [`crate::MacSecHeader`]).
/// MACsec association number (present in the [`crate::MacsecHeader`]).
MacsecAn,
/// MACsec short length (present in the [`crate::MacSecHeader`]).
/// MACsec short length (present in the [`crate::MacsecHeader`]).
MacsecShortLen,
/// IP Fragment offset present in the IPv4 header and
/// IPv6 fragmentation header.
IpFragmentOffset,
/// IPv4 Header DSCP (Differentiated Services Code Point) field
/// present in an [`crate::Ipv4Header`].
Ipv4Dscp,
/// IPv4 Header ECN (Explicit Congestion Notification) field
/// present in an [`crate::Ipv4Header`].
Ipv4Ecn,
/// IPv4 & IPv6 Header DSCP (Differentiated Services Code Point) field
/// present in an [`crate::Ipv4Header`] or [`crate::Ipv6Header`].
IpDscp,
/// IPv6 & IPv6 Header ECN (Explicit Congestion Notification) field
/// present in an [`crate::Ipv4Header`] or [`crate::Ipv6Header`].
IpEcn,
/// IPv6 Header Flow Label field present in [`crate::Ipv6Header`].
Ipv6FlowLabel,
/// IPv4 Header "total length" field based on the payload
Expand Down Expand Up @@ -54,8 +54,8 @@ impl core::fmt::Display for ValueType {
MacsecAn => write!(f, "MACsec AN (Association Number)"),
MacsecShortLen => write!(f, "MACsec SL (Short Length)"),
IpFragmentOffset => write!(f, "IP Fragment Offset"),
Ipv4Dscp => write!(f, "IPv4 DSCP (Differentiated Services Code Point)"),
Ipv4Ecn => write!(f, "IPv4 ECN (Explicit Congestion Notification)"),
IpDscp => write!(f, "IPv4 DSCP (Differentiated Services Code Point)"),
IpEcn => write!(f, "IPv4 ECN (Explicit Congestion Notification)"),
Ipv6FlowLabel => write!(f, "IPv6 Flow Label"),
Ipv4PayloadLength => write!(f, "IPv4 Header 'Payload Length' (sets 'Total Length')"),
Ipv6PayloadLength => write!(f, "IPv6 Header 'Payload Length'"),
Expand Down Expand Up @@ -102,11 +102,11 @@ mod test {
assert_eq!("IP Fragment Offset", &format!("{}", IpFragmentOffset));
assert_eq!(
"IPv4 DSCP (Differentiated Services Code Point)",
&format!("{}", Ipv4Dscp)
&format!("{}", IpDscp)
);
assert_eq!(
"IPv4 ECN (Explicit Congestion Notification)",
&format!("{}", Ipv4Ecn)
&format!("{}", IpEcn)
);
assert_eq!("IPv6 Flow Label", &format!("{}", Ipv6FlowLabel));
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions etherparse/src/lax_sliced_packet_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<'a> LaxSlicedPacketCursor<'a> {
len_source: self.len_source,
payload: vlan_payload.payload,
};
// SAFETY: Safe, as the if at the startt verifies that there is still
// SAFETY: Safe, as the if at the start verifies that there is still
// space in link_exts.
unsafe {
self.result
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'a> LaxSlicedPacketCursor<'a> {

self.offset += macsec.header.header_len();
let macsec_payload = macsec.payload.clone();
// SAFETY: Safe, as the if at the startt verifies that there is still
// SAFETY: Safe, as the if at the start verifies that there is still
// space in link_exts.
unsafe {
self.result
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/link/macsec_an.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::err::ValueTooBigError;

/// 2 bit unsigned integer containing the "MACsec association number".
/// (present in the [`crate::MacSecHeader`]).
/// (present in the [`crate::MacsecHeader`]).
///
/// Identifies up to four SAs within the context of an SC.
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/link/macsec_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl MacsecHeader {
}
}

/// Try creating a [`MacSecHeaderSlice`] from a slice containing the
/// Try creating a [`MacsecHeaderSlice`] from a slice containing the
/// MACsec header & next ether type.
pub fn from_slice(slice: &[u8]) -> Result<MacsecHeader, err::macsec::HeaderSliceError> {
MacsecHeaderSlice::from_slice(slice).map(|v| v.to_header())
Expand Down
4 changes: 2 additions & 2 deletions etherparse/src/link/macsec_header_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct MacsecHeaderSlice<'a> {
}

impl<'a> MacsecHeaderSlice<'a> {
/// Try creating a [`MacSecHeaderSlice`] from a slice containing the
/// Try creating a [`MacsecHeaderSlice`] from a slice containing the
/// MACsec header & next ether type.
pub fn from_slice(
slice: &'a [u8],
Expand Down Expand Up @@ -270,7 +270,7 @@ impl<'a> MacsecHeaderSlice<'a> {
}

/// Decodes all MacSecHeader values and returns them as a
/// [`crate::MacSecHeader`].
/// [`crate::MacsecHeader`].
#[inline]
pub fn to_header(&self) -> MacsecHeader {
MacsecHeader {
Expand Down
4 changes: 2 additions & 2 deletions etherparse/src/link/macsec_short_len.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::err::ValueTooBigError;

/// 6 bit unsigned integer containing the "MACsec short length".
/// (present in the [`crate::MacSecHeader`]).
/// (present in the [`crate::MacsecHeader`]).
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct MacsecShortLen(u8);

Expand Down Expand Up @@ -70,7 +70,7 @@ impl MacsecShortLen {

/// Creates an [`MacsecShortLen`] from a length and automatically
/// defaults to zero if too big. This mirrors the expected behavior
/// of the `short_len` field in the [`MacsecHeader`].
/// of the `short_len` field in the [`crate::MacsecHeader`].
///
/// # Example
/// ```
Expand Down
Loading
Loading