aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-07-24 13:12:34 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-07-24 13:12:34 +0200
commit4625c1b24e371134f98a2ee3a24d63b14f9edb5d (patch)
tree1ab0d03f02b8a0419d078b0a4c0b742cc4037d73
parent2760fc6a47b8234662b535c544fff3f0c777fc13 (diff)
fix false positives introduced by c83af6a74c451d7ba8613105c1df5492123bac2d
-rw-r--r--Cargo.toml1
-rw-r--r--src/de.rs10
-rw-r--r--src/pppoe.rs17
-rw-r--r--src/types.rs3
4 files changed, 18 insertions, 13 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0c94b6d..45b62fd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,5 +7,6 @@ edition = "2021"
[dependencies]
bitfield = "0.14.0"
+peekread = "0.1.1"
ppproperly_macros = { git = "https://github.com/rsdsl/ppproperly_macros.git", version = "0.1.0" }
thiserror = "1.0"
diff --git a/src/de.rs b/src/de.rs
index 0e17150..eb0faa6 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -3,15 +3,17 @@ use crate::Result;
use std::io::Read;
use std::mem;
+use peekread::PeekRead;
+
pub trait Deserialize {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()>;
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()>;
}
macro_rules! impl_deserialize {
($($t:ty) *) => {
$(
impl Deserialize for $t {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
let mut buf = [0; mem::size_of::<$t>()];
r.read_exact(&mut buf)?;
@@ -26,14 +28,14 @@ macro_rules! impl_deserialize {
impl_deserialize!(i8 i16 i32 i64 i128 u8 u16 u32 u64 u128);
impl Deserialize for Vec<u8> {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
r.read_to_end(self)?;
Ok(())
}
}
impl Deserialize for String {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
let mut n = 0u8;
n.deserialize(r)?;
diff --git a/src/pppoe.rs b/src/pppoe.rs
index fc6281b..843c6a3 100644
--- a/src/pppoe.rs
+++ b/src/pppoe.rs
@@ -1,7 +1,8 @@
use crate::{Deserialize, Error, Result, Serialize, VerType};
-use std::io::{Read, Take, Write};
+use std::io::{Read, Seek, SeekFrom, Take, Write};
+use peekread::PeekRead;
use ppproperly_macros::{Deserialize, Serialize};
const ETHER_TYPE_PPPOED: u16 = 0x8863;
@@ -52,7 +53,7 @@ impl Serialize for MACAddr {
}
impl Deserialize for MACAddr {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
let mut buf = Vec::new();
buf.deserialize(&mut r.take(6))?;
@@ -93,7 +94,7 @@ impl Serialize for EtherType {
}
impl Deserialize for EtherType {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
let mut ether_type = 0u16;
ether_type.deserialize(r)?;
@@ -141,7 +142,7 @@ impl Serialize for PPPoECode {
}
impl Deserialize for PPPoECode {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
let mut code = 0u8;
code.deserialize(r)?;
@@ -243,7 +244,7 @@ impl PPPoETagPayload {
}
}
- fn deserialize_with_discriminant<R: Read>(
+ fn deserialize_with_discriminant<R: Read + PeekRead>(
&mut self,
mut r: Take<&mut R>,
discriminant: &u16,
@@ -362,8 +363,8 @@ impl Serialize for [PPPoETag] {
}
impl Deserialize for Vec<PPPoETag> {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
- while r.bytes().count() > 0 {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
+ while r.peek().seek(SeekFrom::End(0))? > 0 {
let mut tmp = PPPoETag::from(PPPoETagPayload::EndOfList);
tmp.deserialize(r)?;
@@ -406,7 +407,7 @@ impl PPPoEPkt {
}
}
- fn deserialize_with_discriminant<R: Read>(
+ fn deserialize_with_discriminant<R: Read + PeekRead>(
&mut self,
mut r: Take<&mut R>,
discriminant: &u8,
diff --git a/src/types.rs b/src/types.rs
index f811525..cdc8614 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -3,6 +3,7 @@ use crate::{Deserialize, Result, Serialize};
use std::io::{Read, Write};
use bitfield::bitfield;
+use peekread::PeekRead;
bitfield! {
/// Version and type of a PPPoE header combined in a single octet.
@@ -29,7 +30,7 @@ impl Serialize for VerType {
}
impl Deserialize for VerType {
- fn deserialize<R: Read>(&mut self, r: &mut R) -> Result<()> {
+ fn deserialize<R: Read + PeekRead>(&mut self, r: &mut R) -> Result<()> {
self.0.deserialize(r)
}
}