diff --git a/Cargo.toml b/Cargo.toml index 6f33fd10f58b6a1e3122eff6ca2b42eb767fa04f..3a8c073ea80236ea5cbd39a24b6349bf18a69b93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ base64 = "0.4.0" minidom = "0.2.0" jid = "0.2.0" sasl = "0.3.0" +sha-1 = "0.3.2" [features] insecure = [] diff --git a/src/component.rs b/src/component.rs index 530a2e30fe05a703fa87727684a1a1016713b5b2..bd5b9ccdb747da04fc96ae46b3de96b774f41005 100644 --- a/src/component.rs +++ b/src/component.rs @@ -5,12 +5,13 @@ use ns; use plugin::{Plugin, PluginProxyBinding}; use event::AbstractEvent; use connection::{Connection, Component2S}; -use openssl::hash::{hash, MessageDigest}; +use sha_1::{Sha1, Digest}; use minidom::Element; use xml::reader::XmlEvent as ReaderEvent; +use std::fmt::Write; use std::sync::mpsc::{Receiver, channel}; /// A builder for `Component`s. @@ -147,11 +148,11 @@ impl Component { } } let concatenated = format!("{}{}", sid, secret); - let hash = hash(MessageDigest::sha1(), concatenated.as_bytes())?; + let mut hasher = Sha1::default(); + hasher.input(concatenated.as_bytes()); let mut handshake = String::new(); - for byte in hash { - // TODO: probably terrible perfs! - handshake = format!("{}{:x}", handshake, byte); + for byte in hasher.result() { + write!(handshake, "{:02x}", byte)?; } let mut elem = Element::builder("handshake") .ns(ns::COMPONENT_ACCEPT) diff --git a/src/error.rs b/src/error.rs index 49a1ce3ea601baa591a514a82b500f6d6fe519e0..036fbe90fa8e24837922dfca1a63b1b4ac89477a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,7 @@ //! Provides an `Error` for use in this crate. +use std::fmt::Error as FormatError; + use std::io; use std::net::TcpStream; @@ -28,6 +30,7 @@ pub enum Error { Base64Error(Base64Error), SaslError(Option), XmppSaslError(SaslError), + FormatError(FormatError), StreamError, EndOfDocument, } @@ -73,3 +76,9 @@ impl From for Error { Error::Base64Error(err) } } + +impl From for Error { + fn from(err: FormatError) -> Error { + Error::FormatError(err) + } +} diff --git a/src/lib.rs b/src/lib.rs index 9f96d034aff07f363cf3489ed23c8e015fd798d7..6a2715fa09bb87541efbd077c5211027d59fb9fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ extern crate xml; extern crate openssl; extern crate minidom; extern crate base64; +extern crate sha_1; pub extern crate jid; pub extern crate sasl;