diff --git a/parsers/src/lib.rs b/parsers/src/lib.rs index a58c0895..2154cb66 100644 --- a/parsers/src/lib.rs +++ b/parsers/src/lib.rs @@ -55,6 +55,8 @@ pub mod sasl; /// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core pub mod stanza_error; /// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core +pub mod starttls; +/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core pub mod stream; /// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core pub mod stream_features; diff --git a/parsers/src/starttls.rs b/parsers/src/starttls.rs new file mode 100644 index 00000000..cb0e9daa --- /dev/null +++ b/parsers/src/starttls.rs @@ -0,0 +1,68 @@ +// Copyright (c) 2018 Emmanuel Gil Peyrot +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +use xso::{AsXml, FromXml}; + +use crate::ns; + +/// Request to start TLS. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::TLS, name = "starttls")] +pub struct Request; + +/// Information that TLS may now commence. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::TLS, name = "proceed")] +pub struct Proceed; + +/// Stream feature for StartTLS +/// +/// Used in [`crate::stream_features::StreamFeatures`]. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::TLS, name = "starttls")] +pub struct StartTls { + /// Marker for mandatory StartTLS. + // TODO: replace with `#[xml(flag)]` once we have it + #[xml(child(default))] + pub required: Option, +} + +/// Marker for mandatory StartTLS. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::TLS, name = "required")] +pub struct RequiredStartTls; + +/// Enum which allows parsing/serialising any STARTTLS element. +#[derive(FromXml, AsXml, Debug, Clone)] +#[xml()] +pub enum Nonza { + /// Request to start TLS + #[xml(transparent)] + Request(Request), + + /// Information that TLS may now commence + #[xml(transparent)] + Proceed(Proceed), +} + +#[cfg(test)] +mod tests { + use super::*; + + #[cfg(target_pointer_width = "32")] + #[test] + fn test_size() { + assert_size!(RequiredStartTls, 0); + assert_size!(StartTls, 1); + } + + #[cfg(target_pointer_width = "64")] + #[test] + fn test_size() { + assert_size!(RequiredStartTls, 0); + assert_size!(StartTls, 1); + } +} diff --git a/parsers/src/stream_features.rs b/parsers/src/stream_features.rs index 930a16b0..1dac2573 100644 --- a/parsers/src/stream_features.rs +++ b/parsers/src/stream_features.rs @@ -11,6 +11,7 @@ use crate::bind::BindFeature; use crate::ns; use crate::sasl2::Authentication; use crate::sasl_cb::SaslChannelBinding; +use crate::starttls::StartTls; use crate::stream_limits::Limits; /// Wraps ``, usually the very first nonza of a @@ -50,20 +51,6 @@ pub struct StreamFeatures { pub others: Vec, } -/// StartTLS is supported, and may be mandatory. -#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] -#[xml(namespace = ns::TLS, name = "starttls")] -pub struct StartTls { - /// Marker for mandatory StartTLS. - #[xml(child(default))] - pub required: Option, -} - -/// Marker for mandatory StartTLS. -#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] -#[xml(namespace = ns::TLS, name = "required")] -pub struct RequiredStartTls; - /// List of supported SASL mechanisms #[derive(FromXml, AsXml, PartialEq, Debug, Clone, Default)] #[xml(namespace = ns::SASL, name = "mechanisms")] @@ -94,8 +81,6 @@ mod tests { #[test] fn test_size() { assert_size!(SaslMechanisms, 12); - assert_size!(RequiredStartTls, 0); - assert_size!(StartTls, 1); assert_size!(StreamFeatures, 92); } @@ -103,8 +88,6 @@ mod tests { #[test] fn test_size() { assert_size!(SaslMechanisms, 24); - assert_size!(RequiredStartTls, 0); - assert_size!(StartTls, 1); assert_size!(StreamFeatures, 168); }