Skip to content

Commit

Permalink
Rework
Browse files Browse the repository at this point in the history
  • Loading branch information
larseggert committed Mar 27, 2024
1 parent a103d0a commit 51c75d9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
1 change: 1 addition & 0 deletions neqo-transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test-fixture = { path = "../test-fixture" }
[features]
bench = []
disable-encryption = ["neqo-crypto/disable-encryption"]
fuzzing = []

[lib]
# See https://github.com/bheisler/criterion.rs/blob/master/book/src/faq.md#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
Expand Down
34 changes: 0 additions & 34 deletions neqo-transport/src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ impl PacketBuilder {
/// Maybe pad with "PADDING" frames.
/// Only does so if padding was needed and this is a short packet.
/// Returns true if padding was added.
///
/// # Panics
///
/// Cannot happen.
pub fn pad(&mut self) -> bool {
if self.padding && !self.is_long() {
self.encoder
Expand Down Expand Up @@ -294,7 +290,6 @@ impl PacketBuilder {
/// The length is filled in after calling `build`.
/// Does nothing if there isn't 4 bytes available other than render this builder
/// unusable; if `remaining()` returns 0 at any point, call `abort()`.
#[allow(clippy::missing_panics_doc)]
pub fn pn(&mut self, pn: PacketNumber, pn_len: usize) {
if self.remaining() < 4 {
self.limit = 0;
Expand Down Expand Up @@ -359,8 +354,6 @@ impl PacketBuilder {
}

/// Build the packet and return the encoder.
#[allow(clippy::missing_errors_doc)]
#[allow(clippy::missing_panics_doc)]
pub fn build(mut self, crypto: &mut CryptoDxState) -> Res<Encoder> {
if self.len() > self.limit {
qwarn!("Packet contents are more than the limit");
Expand Down Expand Up @@ -420,7 +413,6 @@ impl PacketBuilder {
/// As Retry is odd (it has to be constructed with leading bytes),
/// this returns a [`Vec<u8>`] rather than building on an encoder.
#[allow(clippy::similar_names)] // scid and dcid are fine here.
#[allow(clippy::missing_errors_doc)]
pub fn retry(
version: Version,
dcid: &[u8],
Expand Down Expand Up @@ -453,7 +445,6 @@ impl PacketBuilder {

/// Make a Version Negotiation packet.
#[allow(clippy::similar_names)] // scid and dcid are fine here.
#[must_use]
pub fn version_negotiation(
dcid: &[u8],
scid: &[u8],
Expand Down Expand Up @@ -566,8 +557,6 @@ impl<'a> PublicPacket<'a> {
/// Decode the common parts of a packet. This provides minimal parsing and validation.
/// Returns a tuple of a `PublicPacket` and a slice with any remainder from the datagram.
#[allow(clippy::similar_names)] // For dcid and scid, which are fine.
#[allow(clippy::missing_panics_doc)]
#[allow(clippy::missing_errors_doc)]
pub fn decode(data: &'a [u8], dcid_decoder: &dyn ConnectionIdDecoder) -> Res<(Self, &'a [u8])> {
let mut decoder = Decoder::new(data);
let first = Self::opt(decoder.decode_byte())?;
Expand Down Expand Up @@ -658,8 +647,6 @@ impl<'a> PublicPacket<'a> {
}

/// Validate the given packet as though it were a retry.
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn is_valid_retry(&self, odcid: &ConnectionId) -> bool {
if self.packet_type != PacketType::Retry {
return false;
Expand All @@ -680,57 +667,43 @@ impl<'a> PublicPacket<'a> {
.unwrap_or(false)
}

#[must_use]
pub fn is_valid_initial(&self) -> bool {
// Packet has to be an initial, with a DCID of 8 bytes, or a token.
// Note: the Server class validates the token and checks the length.
self.packet_type == PacketType::Initial
&& (self.dcid().len() >= 8 || !self.token.is_empty())
}

#[must_use]
pub fn packet_type(&self) -> PacketType {
self.packet_type
}

#[must_use]
pub fn dcid(&self) -> ConnectionIdRef<'a> {
self.dcid
}

#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn scid(&self) -> ConnectionIdRef<'a> {
self.scid
.expect("should only be called for long header packets")
}

#[must_use]
pub fn token(&self) -> &'a [u8] {
self.token
}

#[must_use]
pub fn version(&self) -> Option<Version> {
self.version.and_then(|v| Version::try_from(v).ok())
}

#[must_use]
pub fn wire_version(&self) -> WireVersion {
debug_assert!(self.version.is_some());
self.version.unwrap_or(0)
}

#[must_use]
pub fn len(&self) -> usize {
self.data.len()
}

#[must_use]
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}

fn decode_pn(expected: PacketNumber, pn: u64, w: usize) -> PacketNumber {
let window = 1_u64 << (w * 8);
let candidate = (expected & !(window - 1)) | pn;
Expand Down Expand Up @@ -805,8 +778,6 @@ impl<'a> PublicPacket<'a> {
))
}

#[allow(clippy::missing_errors_doc)]
#[allow(clippy::missing_panics_doc)]
pub fn decrypt(&self, crypto: &mut CryptoStates, release_at: Instant) -> Res<DecryptedPacket> {
let cspace: CryptoSpace = self.packet_type.into();
// When we don't have a version, the crypto code doesn't need a version
Expand Down Expand Up @@ -844,8 +815,6 @@ impl<'a> PublicPacket<'a> {
}
}

#[allow(clippy::missing_panics_doc)]
#[allow(clippy::missing_errors_doc)]
pub fn supported_versions(&self) -> Res<Vec<WireVersion>> {
assert_eq!(self.packet_type, PacketType::VersionNegotiation);
let mut decoder = Decoder::new(&self.data[self.header_len..]);
Expand Down Expand Up @@ -878,17 +847,14 @@ pub struct DecryptedPacket {
}

impl DecryptedPacket {
#[must_use]
pub fn version(&self) -> Version {
self.version
}

#[must_use]
pub fn packet_type(&self) -> PacketType {
self.pt
}

#[must_use]
pub fn pn(&self) -> PacketNumber {
self.pn
}
Expand Down

0 comments on commit 51c75d9

Please sign in to comment.