summaryrefslogtreecommitdiffstats
path: root/third_party/rust/neqo-common
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/neqo-common')
-rw-r--r--third_party/rust/neqo-common/.cargo-checksum.json2
-rw-r--r--third_party/rust/neqo-common/Cargo.toml13
-rw-r--r--third_party/rust/neqo-common/src/datagram.rs2
-rw-r--r--third_party/rust/neqo-common/src/fuzz.rs43
-rw-r--r--third_party/rust/neqo-common/src/lib.rs4
-rw-r--r--third_party/rust/neqo-common/src/tos.rs27
6 files changed, 86 insertions, 5 deletions
diff --git a/third_party/rust/neqo-common/.cargo-checksum.json b/third_party/rust/neqo-common/.cargo-checksum.json
index 64d5739014..d94920d26f 100644
--- a/third_party/rust/neqo-common/.cargo-checksum.json
+++ b/third_party/rust/neqo-common/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"28a963b1a9067fef18e945a938a6ae5ea14a3a29a937f3be2ec4c0e3ae33854f","benches/timer.rs":"52d35abe1e06b92e913f43d95295b4eded0f19809677a7a63857fe92dad2c6fa","build.rs":"306b2f909a25ae38daf5404a4e128d2a94e8975b70870864c2a71cafec9717c7","src/codec.rs":"fd239f75d374db6ff744211344c82bcd19ecf753e07410e1fe37732bbb81dfe9","src/datagram.rs":"691ad94a3618d6bf5202a7911419b5e75e318d09c8cc57a9a542a864dcc764ec","src/event.rs":"106ca6c4afb107fa49a1bc72f5eb4ae95f4baa1ba19736aa38c8ba973774c160","src/header.rs":"467b947f78bfe354d8bb51e8df0c2be69e75a45e2be688d81f0d268aa77c89ef","src/hrtime.rs":"112dc758e65301b8a7a508b125d3d61063180d432bffaec566a050d4f907ab18","src/incrdecoder.rs":"577c32b9ace51f2daaf940be6d0c391c4f55cd42ef6848c68c1ffc970d8c57b5","src/lib.rs":"c917282134f43d0ddfbd67bbceea9f615a7db8a23608f809b4746808c08a9b3f","src/log.rs":"6ed99e15707c4256ae793011ed2f4b33aa81fed70205aaf5f8d3cd11ad451cf0","src/qlog.rs":"9b081f32bf158fd340300693acc97fe0554b617ae664eba86e4d3572e2b1e16e","src/timer.rs":"f6da86baf3b5d91c1230d5296ef886fb7233cdefa8c8e2b4197fcf82425a54fa","src/tos.rs":"baec87b4f8a6253b88cd257730bd1e3147c046ef993288b08235d54a24f88fbe","tests/log.rs":"a11e21fb570258ca93bb40e3923817d381e1e605accbc3aed1df5a0a9918b41d"},"package":null} \ No newline at end of file
+{"files":{"Cargo.toml":"3459350f69e0272710e4d5d861f9646225f9c187698e721f01d38f2d9b1b3394","benches/timer.rs":"52d35abe1e06b92e913f43d95295b4eded0f19809677a7a63857fe92dad2c6fa","build.rs":"306b2f909a25ae38daf5404a4e128d2a94e8975b70870864c2a71cafec9717c7","src/codec.rs":"fd239f75d374db6ff744211344c82bcd19ecf753e07410e1fe37732bbb81dfe9","src/datagram.rs":"19882ecf3d3b03d6e87a1b8f871429f07f5b0db6d891c9362c91306a0cee33c7","src/event.rs":"106ca6c4afb107fa49a1bc72f5eb4ae95f4baa1ba19736aa38c8ba973774c160","src/fuzz.rs":"1ca74a34bdc97fedecf8a63c4a13cc487d1b2212398fb76f67792c822002138d","src/header.rs":"467b947f78bfe354d8bb51e8df0c2be69e75a45e2be688d81f0d268aa77c89ef","src/hrtime.rs":"112dc758e65301b8a7a508b125d3d61063180d432bffaec566a050d4f907ab18","src/incrdecoder.rs":"577c32b9ace51f2daaf940be6d0c391c4f55cd42ef6848c68c1ffc970d8c57b5","src/lib.rs":"bc585a11daf56f9680fc5a652c5ca79e00eb0f3fa34a45ecd1b6c60200b95cf1","src/log.rs":"6ed99e15707c4256ae793011ed2f4b33aa81fed70205aaf5f8d3cd11ad451cf0","src/qlog.rs":"9b081f32bf158fd340300693acc97fe0554b617ae664eba86e4d3572e2b1e16e","src/timer.rs":"f6da86baf3b5d91c1230d5296ef886fb7233cdefa8c8e2b4197fcf82425a54fa","src/tos.rs":"087cd9b12a2510f05605e755d85c07179817c22670fe1b5d6db987357f77b38e","tests/log.rs":"a11e21fb570258ca93bb40e3923817d381e1e605accbc3aed1df5a0a9918b41d"},"package":null} \ No newline at end of file
diff --git a/third_party/rust/neqo-common/Cargo.toml b/third_party/rust/neqo-common/Cargo.toml
index 90b254c888..0659508aeb 100644
--- a/third_party/rust/neqo-common/Cargo.toml
+++ b/third_party/rust/neqo-common/Cargo.toml
@@ -11,9 +11,9 @@
[package]
edition = "2021"
-rust-version = "1.74.0"
+rust-version = "1.76.0"
name = "neqo-common"
-version = "0.7.5"
+version = "0.7.7"
authors = ["The Neqo Authors <necko@mozilla.com>"]
build = "build.rs"
homepage = "https://github.com/mozilla/neqo/"
@@ -35,12 +35,18 @@ default-features = false
version = "0.10"
default-features = false
+[dependencies.hex]
+version = "0.4"
+features = ["alloc"]
+optional = true
+default-features = false
+
[dependencies.log]
version = "0.4"
default-features = false
[dependencies.qlog]
-version = "0.12"
+version = "0.13"
default-features = false
[dependencies.time]
@@ -57,6 +63,7 @@ default-features = false
path = "../test-fixture"
[features]
+build-fuzzing-corpus = ["hex"]
ci = []
[target."cfg(windows)".dependencies.winapi]
diff --git a/third_party/rust/neqo-common/src/datagram.rs b/third_party/rust/neqo-common/src/datagram.rs
index cc2cb7d113..2f2bb53766 100644
--- a/third_party/rust/neqo-common/src/datagram.rs
+++ b/third_party/rust/neqo-common/src/datagram.rs
@@ -95,6 +95,6 @@ fn fmt_datagram() {
let d = datagram([0; 1].to_vec());
assert_eq!(
&format!("{d:?}"),
- "Datagram IpTos(Cs0, NotEct) TTL Some(128) [fe80::1]:443->[fe80::1]:443: [1]: 00"
+ "Datagram IpTos(Cs0, Ect0) TTL Some(128) [fe80::1]:443->[fe80::1]:443: [1]: 00"
);
}
diff --git a/third_party/rust/neqo-common/src/fuzz.rs b/third_party/rust/neqo-common/src/fuzz.rs
new file mode 100644
index 0000000000..d0a35a49ae
--- /dev/null
+++ b/third_party/rust/neqo-common/src/fuzz.rs
@@ -0,0 +1,43 @@
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::{
+ collections::hash_map::DefaultHasher,
+ fs::File,
+ hash::{Hash, Hasher},
+ io::Write,
+ path::Path,
+};
+
+/// Write a data item `data` for the fuzzing target `target` to the fuzzing corpus. The caller needs
+/// to make sure that `target` is the correct fuzzing target name for the data written.
+///
+/// # Panics
+///
+/// Panics if the corpus directory does not exist or if the corpus item cannot be written.
+pub fn write_item_to_fuzzing_corpus(target: &str, data: &[u8]) {
+ // This bakes in the assumption that we're executing in the root of the neqo workspace.
+ // Unfortunately, `cargo fuzz` doesn't provide a way to learn the location of the corpus
+ // directory.
+ let corpus = Path::new("../fuzz/corpus").join(target);
+ if !corpus.exists() {
+ std::fs::create_dir_all(&corpus).expect("failed to create corpus directory");
+ }
+
+ // Hash the data to get a unique name for the corpus item.
+ let mut hasher = DefaultHasher::new();
+ data.hash(&mut hasher);
+ let item_name = hex::encode(hasher.finish().to_be_bytes());
+ let item_path = corpus.join(item_name);
+ if item_path.exists() {
+ // Don't overwrite existing corpus items.
+ return;
+ }
+
+ // Write the data to the corpus item.
+ let mut file = File::create(item_path).expect("failed to create corpus item");
+ Write::write_all(&mut file, data).expect("failed to write to corpus item");
+}
diff --git a/third_party/rust/neqo-common/src/lib.rs b/third_party/rust/neqo-common/src/lib.rs
index e988c6071d..3a72425e44 100644
--- a/third_party/rust/neqo-common/src/lib.rs
+++ b/third_party/rust/neqo-common/src/lib.rs
@@ -9,6 +9,8 @@
mod codec;
mod datagram;
pub mod event;
+#[cfg(feature = "build-fuzzing-corpus")]
+mod fuzz;
pub mod header;
pub mod hrtime;
mod incrdecoder;
@@ -21,6 +23,8 @@ use std::fmt::Write;
use enum_map::Enum;
+#[cfg(feature = "build-fuzzing-corpus")]
+pub use self::fuzz::write_item_to_fuzzing_corpus;
pub use self::{
codec::{Decoder, Encoder},
datagram::Datagram,
diff --git a/third_party/rust/neqo-common/src/tos.rs b/third_party/rust/neqo-common/src/tos.rs
index 533c5447e2..c7e5228dee 100644
--- a/third_party/rust/neqo-common/src/tos.rs
+++ b/third_party/rust/neqo-common/src/tos.rs
@@ -52,6 +52,16 @@ impl From<IpTos> for IpTosEcn {
}
}
+impl IpTosEcn {
+ #[must_use]
+ pub fn is_ecn_marked(&self) -> bool {
+ match self {
+ IpTosEcn::Ect0 | IpTosEcn::Ect1 | IpTosEcn::Ce => true,
+ IpTosEcn::NotEct => false,
+ }
+ }
+}
+
/// Diffserv Codepoints, mapped to the upper six bits of the TOS field.
/// <https://www.iana.org/assignments/dscp-registry/dscp-registry.xhtml>
#[derive(Copy, Clone, PartialEq, Eq, Enum, Default, Debug)]
@@ -228,6 +238,11 @@ impl IpTos {
pub fn set_dscp(&mut self, dscp: IpTosDscp) {
self.0 = u8::from(IpTosEcn::from(*self)) | u8::from(dscp);
}
+
+ #[must_use]
+ pub fn is_ecn_marked(&self) -> bool {
+ IpTosEcn::from(*self).is_ecn_marked()
+ }
}
#[cfg(test)]
@@ -346,4 +361,16 @@ mod tests {
iptos.set_dscp(IpTosDscp::Le);
assert_eq!(u8::from(iptos), 0b0000_0101);
}
+
+ #[test]
+ fn iptos_is_ecn_marked() {
+ let iptos: IpTos = (IpTosDscp::Af41, IpTosEcn::Ce).into();
+ assert!(iptos.is_ecn_marked());
+ }
+
+ #[test]
+ fn iptosecn_is_ecn_marked() {
+ assert!(IpTosEcn::Ce.is_ecn_marked());
+ assert!(!IpTosEcn::NotEct.is_ecn_marked());
+ }
}