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;
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
35#[cfg(test)]
36mod tests {
37 use super::*;
38 use try_from::TryFrom;
39 use minidom::Element;
40
41 #[test]
42 fn test_simple() {
43 let elem: Element = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'/>".parse().unwrap();
44 let auth = Auth::try_from(elem).unwrap();
45 assert_eq!(auth.mechanism, Mechanism::Plain);
46 assert!(auth.data.is_empty());
47 }
48}