diff --git a/src/params/mod.rs b/src/params/mod.rs index b703075..5e7eb60 100644 --- a/src/params/mod.rs +++ b/src/params/mod.rs @@ -184,14 +184,18 @@ impl FromStr for NoiseParams { #[cfg(not(feature = "hfs"))] fn from_str(s: &str) -> Result { let mut split = s.split('_'); - Ok(NoiseParams::new( + let params = NoiseParams::new( s.to_owned(), split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?, split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?, split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?, split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?, split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?, - )) + ); + if split.next().is_some() { + return Err(PatternProblem::UnsupportedModifier.into()); + } + Ok(params) } #[cfg(feature = "hfs")] @@ -218,6 +222,9 @@ impl FromStr for NoiseParams { split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?, split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?, ); + if split.next().is_some() { + return Err(PatternProblem::UnsupportedModifier.into()); + } // Validate that a KEM is specified iff the hfs modifier is present if p.handshake.is_hfs() != p.kem.is_some() { @@ -332,4 +339,12 @@ mod tests { HandshakeTokens::try_from(&p.handshake).unwrap_err() ); } + + #[test] + fn test_extraneous_string_data() { + assert_eq!( + Error::Pattern(PatternProblem::UnsupportedModifier), + "Noise_XXpsk0_25519_AESGCM_SHA256_HackThePlanet".parse::().unwrap_err() + ); + } }