Skip to content

Commit

Permalink
Error on duplicate modifiers in parameter string
Browse files Browse the repository at this point in the history
  • Loading branch information
mcginty committed Jan 26, 2024
1 parent 8b1a819 commit dbdcc48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/params/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ mod tests {
}
}

#[test]
fn test_duplicate_psk_mod() {
assert!("Noise_XXfallback+psk1_25519_AESGCM_SHA256".parse::<NoiseParams>().is_ok());
assert_eq!(
Error::Pattern(PatternProblem::UnsupportedModifier),
"Noise_XXfallback+fallback_25519_AESGCM_SHA256".parse::<NoiseParams>().unwrap_err()
);
assert_eq!(
Error::Pattern(PatternProblem::UnsupportedModifier),
"Noise_XXpsk1+psk1_25519_AESGCM_SHA256".parse::<NoiseParams>().unwrap_err()
);
}

#[test]
fn test_modified_psk_handshake() {
let p: NoiseParams = "Noise_XXpsk0_25519_AESGCM_SHA256".parse().unwrap();
Expand Down
7 changes: 6 additions & 1 deletion src/params/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ impl FromStr for HandshakeModifierList {
let modifier_names = s.split('+');
let mut modifiers = vec![];
for modifier_name in modifier_names {
modifiers.push(modifier_name.parse()?);
let modifier: HandshakeModifier = modifier_name.parse()?;
if modifiers.contains(&modifier) {
return Err(Error::Pattern(PatternProblem::UnsupportedModifier));
} else {
modifiers.push(modifier);
}
}
Ok(HandshakeModifierList { list: modifiers })
}
Expand Down

0 comments on commit dbdcc48

Please sign in to comment.