1// Copyright (c) 2018 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7use helpers::{Base64, TrimmedPlainText};
8
9generate_attribute!(Mechanism, "mechanism", {
10 Plain => "PLAIN",
11 ScramSha1 => "SCRAM-SHA-1",
12 ScramSha256 => "SCRAM-SHA-256",
13 Anonymous => "ANONYMOUS",
14});
15
16generate_element_with_text!(Auth, "auth", SASL,
17 [
18 mechanism: Mechanism = "mechanism" => required
19 ],
20 data: Base64<Vec<u8>>
21);
22
23generate_element_with_text!(Challenge, "challenge", SASL,
24 data: Base64<Vec<u8>>
25);
26
27generate_element_with_text!(Response, "response", SASL,
28 data: Base64<Vec<u8>>
29);
30
31generate_element_with_text!(Success, "success", SASL,
32 data: Base64<Vec<u8>>
33);
34
35generate_element_with_text!(Failure, "failure", SASL,
36 data: TrimmedPlainText<String>
37);
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42 use try_from::TryFrom;
43 use minidom::Element;
44
45 #[test]
46 fn test_simple() {
47 let elem: Element = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'/>".parse().unwrap();
48 let auth = Auth::try_from(elem).unwrap();
49 assert_eq!(auth.mechanism, Mechanism::Plain);
50 assert!(auth.data.is_empty());
51 }
52}