parsers: add starttls XSOs
This commit is contained in:
parent
3c78310272
commit
54e1a98cde
3 changed files with 71 additions and 18 deletions
|
@ -55,6 +55,8 @@ pub mod sasl;
|
||||||
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||||
pub mod stanza_error;
|
pub mod stanza_error;
|
||||||
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||||
|
pub mod starttls;
|
||||||
|
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||||
pub mod stream;
|
pub mod stream;
|
||||||
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
|
||||||
pub mod stream_features;
|
pub mod stream_features;
|
||||||
|
|
68
parsers/src/starttls.rs
Normal file
68
parsers/src/starttls.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright (c) 2018 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
||||||
|
//
|
||||||
|
// 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<RequiredStartTls>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ use crate::bind::BindFeature;
|
||||||
use crate::ns;
|
use crate::ns;
|
||||||
use crate::sasl2::Authentication;
|
use crate::sasl2::Authentication;
|
||||||
use crate::sasl_cb::SaslChannelBinding;
|
use crate::sasl_cb::SaslChannelBinding;
|
||||||
|
use crate::starttls::StartTls;
|
||||||
use crate::stream_limits::Limits;
|
use crate::stream_limits::Limits;
|
||||||
|
|
||||||
/// Wraps `<stream:features/>`, usually the very first nonza of a
|
/// Wraps `<stream:features/>`, usually the very first nonza of a
|
||||||
|
@ -50,20 +51,6 @@ pub struct StreamFeatures {
|
||||||
pub others: Vec<Element>,
|
pub others: Vec<Element>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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<RequiredStartTls>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Marker for mandatory StartTLS.
|
|
||||||
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
|
|
||||||
#[xml(namespace = ns::TLS, name = "required")]
|
|
||||||
pub struct RequiredStartTls;
|
|
||||||
|
|
||||||
/// List of supported SASL mechanisms
|
/// List of supported SASL mechanisms
|
||||||
#[derive(FromXml, AsXml, PartialEq, Debug, Clone, Default)]
|
#[derive(FromXml, AsXml, PartialEq, Debug, Clone, Default)]
|
||||||
#[xml(namespace = ns::SASL, name = "mechanisms")]
|
#[xml(namespace = ns::SASL, name = "mechanisms")]
|
||||||
|
@ -94,8 +81,6 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_size() {
|
fn test_size() {
|
||||||
assert_size!(SaslMechanisms, 12);
|
assert_size!(SaslMechanisms, 12);
|
||||||
assert_size!(RequiredStartTls, 0);
|
|
||||||
assert_size!(StartTls, 1);
|
|
||||||
assert_size!(StreamFeatures, 92);
|
assert_size!(StreamFeatures, 92);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +88,6 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_size() {
|
fn test_size() {
|
||||||
assert_size!(SaslMechanisms, 24);
|
assert_size!(SaslMechanisms, 24);
|
||||||
assert_size!(RequiredStartTls, 0);
|
|
||||||
assert_size!(StartTls, 1);
|
|
||||||
assert_size!(StreamFeatures, 168);
|
assert_size!(StreamFeatures, 168);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue