From be8c10bb150a5ab3a01e8a298a40447bd7ac6d11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Mar 2026 19:28:31 +0000 Subject: [PATCH 1/4] chore(deps): update snafu requirement from ~0.8 to ~0.9 Updates the requirements on [snafu](https://github.com/shepmaster/snafu) to permit the latest version. - [Changelog](https://github.com/shepmaster/snafu/blob/main/CHANGELOG.md) - [Commits](https://github.com/shepmaster/snafu/compare/0.8.0...0.9.0) --- updated-dependencies: - dependency-name: snafu dependency-version: 0.9.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a55800c..5046d8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ documentation = "https://docs.rs/proxy-protocol/" repository = "https://github.com/Proximyst/proxy-protocol.git" [dependencies] -snafu = "~0.8" +snafu = "~0.9" bytes = "~1" [dev-dependencies] From 09af5e162637f18eb9244c85fc80494ff26b2ce3 Mon Sep 17 00:00:00 2001 From: David Papp Date: Thu, 12 Mar 2026 20:46:06 +0100 Subject: [PATCH 2/4] chore(deps): update rand to version 0.10 and add cargo fmt and test checks to CI --- .github/workflows/build.yml | 2 ++ Cargo.toml | 2 +- src/lib.rs | 1 - src/version1.rs | 9 ++++++--- src/version2.rs | 34 ++++++++++++++++------------------ 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dee9f0b..afac59c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,6 +22,8 @@ jobs: target/ key: ${{ runner.os }}-proxy-protocol-${{ hashFiles('**/Cargo.toml') }} restore-keys: ${{ runner.os }}-proxy-protocol + - run: cargo fmt --check + - run: cargo test -- --include-ignored - run: cargo build - uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index 5046d8c..2652210 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ bytes = "~1" [dev-dependencies] pretty_assertions = "^1.4" -rand = "~0.9" +rand = "~0.10" [features] default = [] diff --git a/src/lib.rs b/src/lib.rs index aafc6d1..8483412 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,6 @@ pub mod version2; use bytes::{Buf, BytesMut}; use snafu::{ensure, ResultExt as _, Snafu}; - #[derive(Debug, Snafu)] #[cfg_attr(not(feature = "always_exhaustive"), non_exhaustive)] // A new version may be added #[cfg_attr(test, derive(PartialEq, Eq))] diff --git a/src/version1.rs b/src/version1.rs index 34b0d66..bbf198c 100644 --- a/src/version1.rs +++ b/src/version1.rs @@ -6,7 +6,6 @@ use std::{ str::{FromStr as _, Utf8Error}, }; - const CR: u8 = 0x0D; const LF: u8 = 0x0A; @@ -120,8 +119,12 @@ pub(crate) fn parse(buf: &mut impl Buf) -> Result IpAddr::V4(Ipv4Addr::from_str(source).context(InvalidAddressSnafu)?), - ProxyAddressFamily::Tcp6 => IpAddr::V6(Ipv6Addr::from_str(source).context(InvalidAddressSnafu)?), + ProxyAddressFamily::Tcp4 => { + IpAddr::V4(Ipv4Addr::from_str(source).context(InvalidAddressSnafu)?) + } + ProxyAddressFamily::Tcp6 => { + IpAddr::V6(Ipv6Addr::from_str(source).context(InvalidAddressSnafu)?) + } ProxyAddressFamily::Unknown => unreachable!("unknown should have its own branch"), }; buf.advance(count); diff --git a/src/version2.rs b/src/version2.rs index 90d7717..1fd735a 100644 --- a/src/version2.rs +++ b/src/version2.rs @@ -3,7 +3,6 @@ use snafu::{ensure, Snafu}; use std::convert::TryInto; use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; - #[derive(Debug, Snafu)] #[cfg_attr(test, derive(PartialEq, Eq))] pub enum ParseError { @@ -228,10 +227,10 @@ impl Tlv for SslExtensionTlv { fn parse_parts(type_id: u8, len: u16, buf: &mut impl Buf) -> Result { Ok(match type_id { PP2_SUBTYPE_SSL_VERSION => Self::Version(ascii_from_buf(buf, len)?), - PP2_SUBTYPE_SSL_CIPHER => Self::Version(ascii_from_buf(buf, len)?), - PP2_SUBTYPE_SSL_SIG_ALG => Self::Version(ascii_from_buf(buf, len)?), - PP2_SUBTYPE_SSL_KEY_ALG => Self::Version(ascii_from_buf(buf, len)?), - PP2_SUBTYPE_SSL_CN => Self::Version(str_from_buf(buf, len)?), + PP2_SUBTYPE_SSL_CIPHER => Self::Cipher(ascii_from_buf(buf, len)?), + PP2_SUBTYPE_SSL_SIG_ALG => Self::SigAlg(ascii_from_buf(buf, len)?), + PP2_SUBTYPE_SSL_KEY_ALG => Self::KeyAlg(ascii_from_buf(buf, len)?), + PP2_SUBTYPE_SSL_CN => Self::ClientCN(str_from_buf(buf, len)?), _ => return InvalidTlvTypeIdSnafu { type_id }.fail(), }) } @@ -249,12 +248,12 @@ impl Ssl { if buf.remaining() < len.into() { return UnexpectedEofSnafu.fail(); } - let mut ext_len = len - .checked_sub(5) - .ok_or_else(|| ParseError::InsufficientLengthSpecified { - given: len.into(), - needs: 5, - })?; + let mut ext_len = + len.checked_sub(5) + .ok_or_else(|| ParseError::InsufficientLengthSpecified { + given: len.into(), + needs: 5, + })?; let client = SslClientFlags(buf.get_u8()); let verify = SslVerifyStatus(buf.get_u32()); let mut extensions = Vec::new(); @@ -584,13 +583,12 @@ pub(crate) fn parse(buf: &mut impl Buf) -> Result Date: Thu, 12 Mar 2026 20:48:34 +0100 Subject: [PATCH 3/4] Refactor error handling in parsing functions for improved readability and consistency --- src/lib.rs | 5 +---- src/version2.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8483412..7197dbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -129,10 +129,7 @@ fn parse_version(buf: &mut impl Buf) -> Result { /// available through [Buf::chunk], at the very least for the header. Data that /// follows may be chunked as you wish. pub fn parse(buf: &mut impl Buf) -> Result { - let version = match parse_version(buf) { - Ok(ver) => ver, - Err(e) => return Err(e), - }; + let version = parse_version(buf)?; Ok(match version { 1 => self::version1::parse(buf).context(Version1Snafu)?, diff --git a/src/version2.rs b/src/version2.rs index 1fd735a..f3157bc 100644 --- a/src/version2.rs +++ b/src/version2.rs @@ -121,7 +121,7 @@ trait Tlv: Sized { let vlen = self.value_len()?; if vlen .checked_add(3) - .map_or(true, |tlv_len| buf.remaining_mut() < tlv_len.into()) + .is_none_or(|tlv_len| buf.remaining_mut() < tlv_len.into()) { return Err(EncodeError::ValueTooLarge); } @@ -147,7 +147,7 @@ trait Tlv: Sized { let expected_rem = buf .remaining() .checked_sub(vlen.into()) - .ok_or_else(|| ParseError::UnexpectedEof)?; + .ok_or(ParseError::UnexpectedEof)?; let r = Self::parse_parts(type_id, vlen, buf)?; // Assert, because it would be an internal error assert_eq!(buf.remaining(), expected_rem); @@ -500,7 +500,7 @@ pub(crate) fn parse(buf: &mut impl Buf) -> Result Result Date: Thu, 12 Mar 2026 20:50:38 +0100 Subject: [PATCH 4/4] Refactor error handling in `parse` function for improved readability --- src/version2.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/version2.rs b/src/version2.rs index f3157bc..238085c 100644 --- a/src/version2.rs +++ b/src/version2.rs @@ -583,12 +583,13 @@ pub(crate) fn parse(buf: &mut impl Buf) -> Result