diff --git a/rust/src/encryption.rs b/rust/src/encryption.rs index c0482aa6ac..b9620b7e27 100644 --- a/rust/src/encryption.rs +++ b/rust/src/encryption.rs @@ -23,3 +23,16 @@ pub enum EncryptionHandling { ENCRYPTION_HANDLING_BYPASS = 1, // Skip processing of flow, bypass if possible ENCRYPTION_HANDLING_FULL = 2, // Handle fully like any other protocol } + +impl std::str::FromStr for EncryptionHandling { + type Err = (); + + fn from_str(s: &str) -> Result { + match s { + "full" => Ok(EncryptionHandling::ENCRYPTION_HANDLING_FULL), + "track-only" => Ok(EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY), + "bypass" => Ok(EncryptionHandling::ENCRYPTION_HANDLING_BYPASS), + _ => Err(()), + } + } +} \ No newline at end of file diff --git a/rust/src/quic/quic.rs b/rust/src/quic/quic.rs index b42c920d87..fd19a663d0 100644 --- a/rust/src/quic/quic.rs +++ b/rust/src/quic/quic.rs @@ -35,6 +35,7 @@ use crate::{ }; use std::collections::VecDeque; use std::ffi::CString; +use std::str::FromStr; use suricata_sys::sys::{ AppLayerParserState, AppProto, SCAppLayerParserConfParserEnabled, SCAppLayerParserRegisterLogger, SCAppLayerParserStateSetFlag, @@ -614,16 +615,11 @@ pub unsafe extern "C" fn SCRegisterQuicParser() { if SCAppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 { let _ = AppLayerRegisterParser(&parser, alproto); if let Some(val) = conf_get("app-layer.protocols.quic.encryption-handling") { - let eh = match val { - "full" => EncryptionHandling::ENCRYPTION_HANDLING_FULL, - "track-only" => EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY, - "bypass" => EncryptionHandling::ENCRYPTION_HANDLING_BYPASS, - _ => { - SCFatalErrorOnInit!("Unknown value {} for quic.encryption-handling.", val); - EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY - } - }; - unsafe { ENCRYPTION_BYPASS_ENABLED = eh }; + if let Ok(eh) = EncryptionHandling::from_str(val) { + unsafe { ENCRYPTION_BYPASS_ENABLED = eh }; + } else { + SCFatalErrorOnInit!("Unknown value {} for quic.encryption-handling.", val); + } } } SCLogDebug!("Rust quic parser registered.");