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!(Auth, "auth", SASL,
17 attributes: [
18 mechanism: Mechanism = "mechanism" => required
19 ],
20 text: (
21 data: Base64<Vec<u8>>
22 )
23);
24
25generate_element!(Challenge, "challenge", SASL,
26 text: (
27 data: Base64<Vec<u8>>
28 )
29);
30
31generate_element!(Response, "response", SASL,
32 text: (
33 data: Base64<Vec<u8>>
34 )
35);
36
37generate_element!(Success, "success", SASL,
38 text: (
39 data: Base64<Vec<u8>>
40 )
41);
42
43generate_element!(Failure, "failure", SASL,
44 text: (
45 data: TrimmedPlainText<String>
46 )
47);
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52 use try_from::TryFrom;
53 use minidom::Element;
54
55 #[test]
56 fn test_simple() {
57 let elem: Element = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'/>".parse().unwrap();
58 let auth = Auth::try_from(elem).unwrap();
59 assert_eq!(auth.mechanism, Mechanism::Plain);
60 assert!(auth.data.is_empty());
61 }
62}