Skip to content

Commit

Permalink
Remove superfluous freestanding connection ID parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed May 22, 2024
1 parent 696deb7 commit 9d10813
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ extern crate proto;
use libfuzzer_sys::fuzz_target;
use proto::{
fuzzing::{PacketParams, PartialDecode},
FixedLengthConnectionIdParser, DEFAULT_SUPPORTED_VERSIONS,
RandomConnectionIdGenerator, DEFAULT_SUPPORTED_VERSIONS,
};

fuzz_target!(|data: PacketParams| {
let len = data.buf.len();
let supported_versions = DEFAULT_SUPPORTED_VERSIONS.to_vec();
if let Ok(decoded) = PartialDecode::new(
data.buf,
&FixedLengthConnectionIdParser::new(data.local_cid_len),
&RandomConnectionIdGenerator::new(data.local_cid_len),
&supported_versions,
data.grease_quic_bit,
) {
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ pub use crate::endpoint::{

mod packet;
pub use packet::{
ConnectionIdParser, FixedLengthConnectionIdParser, LongType, PacketDecodeError, PartialDecode,
ProtectedHeader, ProtectedInitialHeader,
ConnectionIdParser, LongType, PacketDecodeError, PartialDecode, ProtectedHeader,
ProtectedInitialHeader,
};

mod shared;
Expand Down
20 changes: 0 additions & 20 deletions quinn-proto/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,26 +767,6 @@ impl PacketNumber {
}
}

/// A [`ConnectionIdParser`] implementation that assumes the connection ID is of fixed length
pub struct FixedLengthConnectionIdParser {
expected_len: usize,
}

impl FixedLengthConnectionIdParser {
/// Create a new instance of `FixedLengthConnectionIdParser`
pub fn new(expected_len: usize) -> Self {
Self { expected_len }
}
}

impl ConnectionIdParser for FixedLengthConnectionIdParser {
fn parse(&self, buffer: &mut dyn Buf) -> Result<ConnectionId, PacketDecodeError> {
(buffer.remaining() >= self.expected_len)
.then(|| ConnectionId::from_buf(buffer, self.expected_len))
.ok_or(PacketDecodeError::InvalidHeader("packet too small"))
}
}

/// Parse connection id in short header packet
pub trait ConnectionIdParser {
/// Parse a connection id from given buffer
Expand Down

0 comments on commit 9d10813

Please sign in to comment.