aboutsummaryrefslogtreecommitdiffstats
path: root/src/stanza/sasl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/stanza/sasl.rs')
-rw-r--r--src/stanza/sasl.rs84
1 files changed, 80 insertions, 4 deletions
diff --git a/src/stanza/sasl.rs b/src/stanza/sasl.rs
index 6ac4fc9..ec6f63c 100644
--- a/src/stanza/sasl.rs
+++ b/src/stanza/sasl.rs
@@ -105,10 +105,10 @@ impl FromElement for Challenge {
}
#[derive(Debug)]
-pub struct Success(String);
+pub struct Success(Option<String>);
impl Deref for Success {
- type Target = str;
+ type Target = Option<String>;
fn deref(&self) -> &Self::Target {
&self.0
@@ -120,7 +120,7 @@ impl FromElement for Success {
element.check_name("success")?;
element.check_namespace(XMLNS)?;
- let sasl_data = element.value()?;
+ let sasl_data = element.value_opt()?;
Ok(Success(sasl_data))
}
@@ -130,10 +130,12 @@ impl FromElement for Success {
pub enum ServerResponse {
Challenge(Challenge),
Success(Success),
+ Failure(Failure),
}
impl FromElement for ServerResponse {
fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ debug!("identification: {:?}", element.identify());
match element.identify() {
(Some(XMLNS), "challenge") => {
Ok(ServerResponse::Challenge(Challenge::from_element(element)?))
@@ -141,6 +143,9 @@ impl FromElement for ServerResponse {
(Some(XMLNS), "success") => {
Ok(ServerResponse::Success(Success::from_element(element)?))
}
+ (Some(XMLNS), "failure") => {
+ Ok(ServerResponse::Failure(Failure::from_element(element)?))
+ }
_ => Err(DeserializeError::UnexpectedElement(element)),
}
}
@@ -165,6 +170,77 @@ impl Deref for Response {
impl IntoElement for Response {
fn builder(&self) -> peanuts::element::ElementBuilder {
- Element::builder("reponse", Some(XMLNS)).push_text(self.0.clone())
+ Element::builder("response", Some(XMLNS)).push_text(self.0.clone())
+ }
+}
+
+#[derive(Debug)]
+pub struct Failure {
+ r#type: Option<FailureType>,
+ text: Option<Text>,
+}
+
+impl FromElement for Failure {
+ fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ element.check_name("failure")?;
+ element.check_namespace(XMLNS)?;
+
+ let r#type = element.pop_child_opt()?;
+ let text = element.pop_child_opt()?;
+
+ Ok(Failure { r#type, text })
+ }
+}
+
+#[derive(Debug)]
+pub enum FailureType {
+ Aborted,
+ AccountDisabled,
+ CredentialsExpired,
+ EncryptionRequired,
+ IncorrectEncoding,
+ InvalidAuthzid,
+ InvalidMechanism,
+ MalformedRequest,
+ MechanismTooWeak,
+ NotAuthorized,
+ TemporaryAuthFailure,
+}
+
+impl FromElement for FailureType {
+ fn from_element(element: Element) -> peanuts::element::DeserializeResult<Self> {
+ match element.identify() {
+ (Some(XMLNS), "aborted") => Ok(FailureType::Aborted),
+ (Some(XMLNS), "account-disabled") => Ok(FailureType::AccountDisabled),
+ (Some(XMLNS), "credentials-expired") => Ok(FailureType::CredentialsExpired),
+ (Some(XMLNS), "encryption-required") => Ok(FailureType::EncryptionRequired),
+ (Some(XMLNS), "incorrect-encoding") => Ok(FailureType::IncorrectEncoding),
+ (Some(XMLNS), "invalid-authzid") => Ok(FailureType::InvalidAuthzid),
+ (Some(XMLNS), "invalid-mechanism") => Ok(FailureType::InvalidMechanism),
+ (Some(XMLNS), "malformed-request") => Ok(FailureType::MalformedRequest),
+ (Some(XMLNS), "mechanism-too-weak") => Ok(FailureType::MechanismTooWeak),
+ (Some(XMLNS), "not-authorized") => Ok(FailureType::NotAuthorized),
+ (Some(XMLNS), "temporary-auth-failure") => Ok(FailureType::TemporaryAuthFailure),
+ _ => Err(DeserializeError::UnexpectedElement(element)),
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct Text {
+ lang: Option<String>,
+ text: Option<String>,
+}
+
+impl FromElement for Text {
+ fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
+ element.check_name("text")?;
+ element.check_namespace(XMLNS)?;
+
+ let lang = element.attribute_opt_namespaced("lang", peanuts::XML_NS)?;
+
+ let text = element.pop_value_opt()?;
+
+ Ok(Text { lang, text })
}
}