2018-02-20 16:01:12 +00:00
|
|
|
// 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 helpers::Base64;
|
|
|
|
|
|
|
|
generate_attribute!(Mechanism, "mechanism", {
|
|
|
|
Plain => "PLAIN",
|
|
|
|
ScramSha1 => "SCRAM-SHA-1",
|
2018-08-02 16:16:10 +00:00
|
|
|
ScramSha256 => "SCRAM-SHA-256",
|
2018-02-20 16:01:12 +00:00
|
|
|
Anonymous => "ANONYMOUS",
|
|
|
|
});
|
|
|
|
|
2018-05-14 14:30:28 +00:00
|
|
|
generate_element_with_text!(Auth, "auth", SASL,
|
2018-02-20 16:01:12 +00:00
|
|
|
[
|
|
|
|
mechanism: Mechanism = "mechanism" => required
|
|
|
|
],
|
|
|
|
data: Base64<Vec<u8>>
|
|
|
|
);
|
|
|
|
|
2018-05-14 14:30:28 +00:00
|
|
|
generate_element_with_text!(Challenge, "challenge", SASL,
|
2018-02-20 16:01:12 +00:00
|
|
|
data: Base64<Vec<u8>>
|
|
|
|
);
|
|
|
|
|
2018-05-14 14:30:28 +00:00
|
|
|
generate_element_with_text!(Response, "response", SASL,
|
2018-02-20 16:01:12 +00:00
|
|
|
data: Base64<Vec<u8>>
|
|
|
|
);
|
|
|
|
|
2018-05-14 14:30:28 +00:00
|
|
|
generate_element_with_text!(Success, "success", SASL,
|
2018-02-20 16:01:12 +00:00
|
|
|
data: Base64<Vec<u8>>
|
|
|
|
);
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2018-05-14 14:07:15 +00:00
|
|
|
use try_from::TryFrom;
|
2018-05-14 14:17:21 +00:00
|
|
|
use minidom::Element;
|
2018-02-20 16:01:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simple() {
|
|
|
|
let elem: Element = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'/>".parse().unwrap();
|
|
|
|
let auth = Auth::try_from(elem).unwrap();
|
|
|
|
assert_eq!(auth.mechanism, Mechanism::Plain);
|
|
|
|
assert!(auth.data.is_empty());
|
|
|
|
}
|
|
|
|
}
|