From 27e449915394e4dbe078b07c17aac4f8cc6cb248 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 8 Aug 2024 14:50:13 +0200 Subject: [PATCH] xmpp-parsers: Simplify SASL mechanisms type These can be a simple String for now. --- parsers/src/stream_features.rs | 36 +++++++++++++++++++++------------- tokio-xmpp/src/client/auth.rs | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/parsers/src/stream_features.rs b/parsers/src/stream_features.rs index c5a11fee..7f7f3fb8 100644 --- a/parsers/src/stream_features.rs +++ b/parsers/src/stream_features.rs @@ -58,18 +58,9 @@ pub struct RequiredStartTls; #[derive(FromXml, AsXml, PartialEq, Debug, Clone, Default)] #[xml(namespace = ns::SASL, name = "mechanisms")] pub struct SaslMechanisms { - /// List of information elements describing this avatar. - #[xml(child(n = ..))] - pub mechanisms: Vec, -} - -/// The name of a SASL mechanism. -#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] -#[xml(namespace = ns::SASL, name = "mechanism")] -pub struct SaslMechanism { - /// The stringy name of the mechanism. - #[xml(text)] - pub mechanism: String, + /// List of information elements describing this SASL mechanism. + #[xml(extract(n = .., name = "mechanism", fields(text(type_ = String))))] + pub mechanisms: Vec, } impl StreamFeatures { @@ -92,7 +83,6 @@ mod tests { #[cfg(target_pointer_width = "32")] #[test] fn test_size() { - assert_size!(SaslMechanism, 12); assert_size!(SaslMechanisms, 12); assert_size!(RequiredStartTls, 0); assert_size!(StartTls, 1); @@ -102,13 +92,31 @@ mod tests { #[cfg(target_pointer_width = "64")] #[test] fn test_size() { - assert_size!(SaslMechanism, 24); assert_size!(SaslMechanisms, 24); assert_size!(RequiredStartTls, 0); assert_size!(StartTls, 1); assert_size!(StreamFeatures, 64); } + #[test] + fn test_sasl_mechanisms() { + let elem: Element = " + + PLAIN + SCRAM-SHA-1 + SCRAM-SHA-1-PLUS + + " + .parse() + .unwrap(); + + let features = StreamFeatures::try_from(elem).unwrap(); + assert_eq!( + features.sasl_mechanisms.mechanisms, + ["PLAIN", "SCRAM-SHA-1", "SCRAM-SHA-1-PLUS"] + ); + } + #[test] fn test_required_starttls() { let elem: Element = " diff --git a/tokio-xmpp/src/client/auth.rs b/tokio-xmpp/src/client/auth.rs index 437ec799..39292a49 100644 --- a/tokio-xmpp/src/client/auth.rs +++ b/tokio-xmpp/src/client/auth.rs @@ -28,7 +28,7 @@ pub async fn auth( .sasl_mechanisms .mechanisms .iter() - .map(|item| item.mechanism.clone()) + .cloned() .collect(); for local_mech in local_mechs {