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 Anonymous => "ANONYMOUS",
13});
14
15generate_element_with_text!(Auth, "auth", SASL,
16 [
17 mechanism: Mechanism = "mechanism" => required
18 ],
19 data: Base64<Vec<u8>>
20);
21
22generate_element_with_text!(Challenge, "challenge", SASL,
23 data: Base64<Vec<u8>>
24);
25
26generate_element_with_text!(Response, "response", SASL,
27 data: Base64<Vec<u8>>
28);
29
30generate_element_with_text!(Success, "success", SASL,
31 data: Base64<Vec<u8>>
32);
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use try_from::TryFrom;
38 use minidom::Element;
39
40 #[test]
41 fn test_simple() {
42 let elem: Element = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'/>".parse().unwrap();
43 let auth = Auth::try_from(elem).unwrap();
44 assert_eq!(auth.mechanism, Mechanism::Plain);
45 assert!(auth.data.is_empty());
46 }
47}