Skip to content

Commit

Permalink
Test CI via update to RELEASE_NOTES
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-bennett committed Sep 10, 2024
1 parent 9fc8ff0 commit 74d3437
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 180 deletions.
11 changes: 6 additions & 5 deletions pkts-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ impl<'a> BufferMut<'a> {
&self.buf[..self.buf_len]
}


#[inline]
pub fn as_mut_slice(&mut self) -> &mut [u8] {
&mut self.buf[..self.buf_len]
}


/// Appends the provided bytes to the buffer, panicking if insufficient space is available in
/// the buffer.
Expand All @@ -120,7 +118,10 @@ impl<'a> BufferMut<'a> {
/// available in the buffer.
#[inline]
pub fn append_or<T>(&mut self, bytes: &[u8], error: T) -> Result<(), T> {
let buf_slice = self.buf.get_mut(self.buf_len..self.buf_len + bytes.len()).ok_or(error)?;
let buf_slice = self
.buf
.get_mut(self.buf_len..self.buf_len + bytes.len())
.ok_or(error)?;
buf_slice.copy_from_slice(bytes);
self.buf_len += bytes.len();
Ok(())
Expand All @@ -131,10 +132,10 @@ impl<'a> BufferMut<'a> {
#[inline]
pub fn try_append(&mut self, bytes: &[u8]) -> Option<()> {
if self.remaining() < bytes.len() {
return None
return None;
} else {
self.append(bytes);
return Some(())
return Some(());
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkts/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History:

* 0.2.0
- Split out `rscap` and `pkts` into separate crates
- Introduce CI pipeline

* 0.1.3
- Switched license to MIT/Apache 2.0
- Additional documentation
Expand Down
15 changes: 7 additions & 8 deletions pkts/src/layers/diameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use alloc::boxed::Box;
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::vec::Vec;


use bitflags::bitflags;

#[derive(Clone, Debug, Layer, StatelessLayer)]
Expand Down Expand Up @@ -247,8 +246,7 @@ impl<'a> DiameterRef<'a> {

#[inline]
pub fn unpadded_len(&self) -> u32 {
0x_00FF_FFFF
& u32::from_be_bytes(utils::to_array(self.data, 0).unwrap())
0x_00FF_FFFF & u32::from_be_bytes(utils::to_array(self.data, 0).unwrap())
}

#[inline]
Expand All @@ -258,8 +256,7 @@ impl<'a> DiameterRef<'a> {

#[inline]
pub fn comm_code(&self) -> u32 {
0x_00FF_FFFF
& u32::from_be_bytes(utils::to_array(self.data, 4).unwrap())
0x_00FF_FFFF & u32::from_be_bytes(utils::to_array(self.data, 4).unwrap())
}

#[inline]
Expand All @@ -280,7 +277,7 @@ impl<'a> DiameterRef<'a> {
#[inline]
pub fn avp_iter(&self) -> AvpIterRef<'a> {
AvpIterRef {
bytes: &self.data[20..]
bytes: &self.data[20..],
}
}
}
Expand Down Expand Up @@ -392,7 +389,8 @@ impl<'a> Iterator for AvpIterRef<'a> {
return None;
}

let unpadded_len = 0x_00FF_FFFF & u32::from_be_bytes(utils::to_array(self.bytes, 4).unwrap());
let unpadded_len =
0x_00FF_FFFF & u32::from_be_bytes(utils::to_array(self.bytes, 4).unwrap());
let len = cmp::max(utils::padded_length::<4>(unpadded_len as usize), 12);
let opt = GenericAvpRef::from_bytes_unchecked(&self.bytes[..len]);
self.bytes = &self.bytes[len..];
Expand Down Expand Up @@ -1138,7 +1136,8 @@ impl<'a> Iterator for BaseAvpIterRef<'a> {
return None;
}

let unpadded_len = 0x_00FF_FFFF & u32::from_be_bytes(utils::to_array(self.bytes, 4).unwrap());
let unpadded_len =
0x_00FF_FFFF & u32::from_be_bytes(utils::to_array(self.bytes, 4).unwrap());
let len = cmp::max(utils::padded_length::<4>(unpadded_len as usize), 12);
let opt = BaseAvpRef::from_bytes_unchecked(&self.bytes[..len]);
self.bytes = &self.bytes[len..];
Expand Down
38 changes: 32 additions & 6 deletions pkts/src/layers/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@ impl Ipv4 {
#[inline]
pub fn ihl(&self) -> u8 {
let len = self.options.byte_len();
assert!(len < (10 * 4), "too many options in Ipv4 to represent in the Internet Header Length (IHL) field");
assert!(
len < (10 * 4),
"too many options in Ipv4 to represent in the Internet Header Length (IHL) field"
);
5 + (len / 4) as u8
}

Expand Down Expand Up @@ -2154,7 +2157,8 @@ impl<'a> Ipv6Ref<'a> {
#[inline]
pub fn flow_label(&self) -> FlowLabel {
FlowLabel {
value: (((self.data[1] & 0x0F) as u32) << 16) + u16::from_be_bytes(utils::to_array(self.data, 2).unwrap()) as u32
value: (((self.data[1] & 0x0F) as u32) << 16)
+ u16::from_be_bytes(utils::to_array(self.data, 2).unwrap()) as u32,
}
}

Expand Down Expand Up @@ -2197,15 +2201,37 @@ impl<'a> Ipv6Ref<'a> {
/// The source IP address of the packet.
#[inline]
pub fn src(&self) -> Ipv6Addr {
let segments: [u16; 8] = array::from_fn(|i| u16::from_be_bytes(utils::to_array(self.data, 8 + (i * 2)).unwrap()));
Ipv6Addr::new(segments[0], segments[1], segments[2], segments[3], segments[4], segments[5], segments[6], segments[7])
let segments: [u16; 8] = array::from_fn(|i| {
u16::from_be_bytes(utils::to_array(self.data, 8 + (i * 2)).unwrap())
});
Ipv6Addr::new(
segments[0],
segments[1],
segments[2],
segments[3],
segments[4],
segments[5],
segments[6],
segments[7],
)
}

/// The destination IP address of the packet.
#[inline]
pub fn dst(&self) -> Ipv6Addr {
let segments: [u16; 8] = array::from_fn(|i| u16::from_be_bytes(utils::to_array(self.data, 24 + (i * 2)).unwrap()));
Ipv6Addr::new(segments[0], segments[1], segments[2], segments[3], segments[4], segments[5], segments[6], segments[7])
let segments: [u16; 8] = array::from_fn(|i| {
u16::from_be_bytes(utils::to_array(self.data, 24 + (i * 2)).unwrap())
});
Ipv6Addr::new(
segments[0],
segments[1],
segments[2],
segments[3],
segments[4],
segments[5],
segments[6],
segments[7],
)
}

/// The payload of the packet, in raw bytes.
Expand Down
3 changes: 1 addition & 2 deletions pkts/src/layers/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ impl<'a> MysqlPacketRef<'a> {

#[inline]
pub fn sequence_id(&self) -> u8 {
self
.data[3]
self.data[3]
}

#[inline]
Expand Down
11 changes: 7 additions & 4 deletions pkts/src/layers/psql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ impl DescribePrepared {

#[derive(Clone, Debug)]
pub struct Execute {
portal_name: CString, // empty string means unnamed portal
portal_name: CString, // empty string means unnamed portal
max_rows: Option<i32>, // None corresponds to 0
}

Expand Down Expand Up @@ -737,7 +737,10 @@ impl Parse {

#[inline]
pub fn len(&self) -> usize {
5 + self.dst_stmt.as_bytes().len() + self.query.as_bytes().len() + 2 + 4 * self.type_ids.len()
5 + self.dst_stmt.as_bytes().len()
+ self.query.as_bytes().len()
+ 2
+ 4 * self.type_ids.len()
}

#[inline]
Expand Down Expand Up @@ -878,8 +881,8 @@ impl StartupMessage {

#[derive(Clone, Debug)]
pub struct Bind {
dst_portal: CString, // empty indicates unnamed portal
src_prepared: CString, // empty indicates the unnamed prepared statement
dst_portal: CString, // empty indicates unnamed portal
src_prepared: CString, // empty indicates the unnamed prepared statement
params_fmt: Vec<FormatCode>, // 0 indicates text; 1 indicates binary.
params: Vec<Option<Vec<u8>>>, // None means null parameter value
results_fmt: Vec<FormatCode>,
Expand Down
4 changes: 2 additions & 2 deletions pkts/src/layers/sctp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2660,9 +2660,9 @@ impl<'a> HeartbeatChunkRef<'a> {
reason: "insufficient bytes in SCTP HEARTBEAT chunk for header + Heartbeat Info option",
});
}

#[allow(unused_variables)]
if let Err( e) = HeartbeatInfoRef::validate(&bytes[4..len]) {
if let Err(e) = HeartbeatInfoRef::validate(&bytes[4..len]) {
return Err(ValidationError {
layer: Sctp::name(),
class: ValidationErrorClass::InvalidValue,
Expand Down
Loading

0 comments on commit 74d3437

Please sign in to comment.