diff --git a/src/algorithm.rs b/src/algorithm.rs index 7546841..becd6e0 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -36,7 +36,7 @@ pub fn negotiate(server: &[A], client: &[A]) return Ok(*algorithm); } } - Err(ConnectionError::NegotiationError) + Err(ConnectionError::Negotiation) } #[derive(Clone, Copy, PartialEq, Debug)] @@ -99,19 +99,19 @@ impl FromStr for KeyExchangeAlgorithm { impl fmt::Display for KeyExchangeAlgorithm { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::KeyExchangeAlgorithm::*; - f.write_str(match self + f.write_str(match *self { - &CURVE25519_SHA256 => "curve25519-sha256", - &ECDH_SHA2_NISTP256 => "ecdh-sha2-nistp256", - &ECDH_SHA2_NISTP384 => "ecdh-sha2-nistp384", - &ECDH_SHA2_NISTP521 => "ecdh-sha2-nistp521", - &DH_GROUP_EXCHANGE_SHA256 => "diffie-hellman-group-exchange-sha256", - &DH_GROUP_EXCHANGE_SHA1 => "diffie-hellman-group-exchange-sha1", - &DH_GROUP16_SHA512 => "diffie-hellman-group16-sha512", - &DH_GROUP18_SHA512 => "diffie-hellman-group18-sha512", - &DH_GROUP14_SHA256 => "diffie-hellman-group14-sha256", - &DH_GROUP14_SHA1 => "diffie-hellman-group14-sha1", - &EXT_INFO_C => "ext-info-c", + CURVE25519_SHA256 => "curve25519-sha256", + ECDH_SHA2_NISTP256 => "ecdh-sha2-nistp256", + ECDH_SHA2_NISTP384 => "ecdh-sha2-nistp384", + ECDH_SHA2_NISTP521 => "ecdh-sha2-nistp521", + DH_GROUP_EXCHANGE_SHA256 => "diffie-hellman-group-exchange-sha256", + DH_GROUP_EXCHANGE_SHA1 => "diffie-hellman-group-exchange-sha1", + DH_GROUP16_SHA512 => "diffie-hellman-group16-sha512", + DH_GROUP18_SHA512 => "diffie-hellman-group18-sha512", + DH_GROUP14_SHA256 => "diffie-hellman-group14-sha256", + DH_GROUP14_SHA1 => "diffie-hellman-group14-sha1", + EXT_INFO_C => "ext-info-c", }) } } @@ -152,15 +152,15 @@ impl FromStr for PublicKeyAlgorithm { impl fmt::Display for PublicKeyAlgorithm { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::PublicKeyAlgorithm::*; - f.write_str(match self + f.write_str(match *self { - &SSH_RSA => "ssh-rsa", - &RSA_SHA2_256 => "rsa-sha2-256", - &RSA_SHA2_512 => "rsa-sha2-512", - &ECDSA_SHA2_NISTP256 => "ecdsa-sha2-nistp256", - &ECDSA_SHA2_NISTP384 => "ecdsa-sha2-nistp384", - &ECDSA_SHA2_NISTP521 => "ecdsa-sha2-nistp521", - &SSH_ED25519 => "ssh-ed25519", + SSH_RSA => "ssh-rsa", + RSA_SHA2_256 => "rsa-sha2-256", + RSA_SHA2_512 => "rsa-sha2-512", + ECDSA_SHA2_NISTP256 => "ecdsa-sha2-nistp256", + ECDSA_SHA2_NISTP384 => "ecdsa-sha2-nistp384", + ECDSA_SHA2_NISTP521 => "ecdsa-sha2-nistp521", + SSH_ED25519 => "ssh-ed25519", }) } } @@ -201,15 +201,15 @@ impl FromStr for EncryptionAlgorithm { impl fmt::Display for EncryptionAlgorithm { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::EncryptionAlgorithm::*; - f.write_str(match self + f.write_str(match *self { - &AES128_CTR => "aes128-ctr", - &AES128_CBC => "aes128-cbc", - &AES192_CTR => "aes192-ctr", - &AES192_CBC => "aes192-cbc", - &AES256_CTR => "aes256-ctr", - &AES256_CBC => "aes256-cbc", - &EncryptionAlgorithm::None => "none", + AES128_CTR => "aes128-ctr", + AES128_CBC => "aes128-cbc", + AES192_CTR => "aes192-ctr", + AES192_CBC => "aes192-cbc", + AES256_CTR => "aes256-ctr", + AES256_CBC => "aes256-cbc", + EncryptionAlgorithm::None => "none", }) } } @@ -244,12 +244,12 @@ impl FromStr for MacAlgorithm { impl fmt::Display for MacAlgorithm { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::MacAlgorithm::*; - f.write_str(match self + f.write_str(match *self { - &HMAC_SHA1 => "hmac-sha1", - &HMAC_SHA2_256 => "hmac-sha2-256", - &HMAC_SHA2_512 => "hmac-sha2-512", - &MacAlgorithm::None => "none", + HMAC_SHA1 => "hmac-sha1", + HMAC_SHA2_256 => "hmac-sha2-256", + HMAC_SHA2_512 => "hmac-sha2-512", + MacAlgorithm::None => "none", }) } } @@ -277,10 +277,10 @@ impl FromStr for CompressionAlgorithm { impl fmt::Display for CompressionAlgorithm { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(match self + f.write_str(match *self { - &CompressionAlgorithm::Zlib => "zlib", - &CompressionAlgorithm::None => "none", + CompressionAlgorithm::Zlib => "zlib", + CompressionAlgorithm::None => "none", }) } } diff --git a/src/connection.rs b/src/connection.rs index e501d35..106f2f9 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -46,7 +46,7 @@ pub struct Connection { channels: BTreeMap, } -impl<'a> Connection { +impl Connection { pub fn new(conn_type: ConnectionType) -> Connection { Connection { conn_type, @@ -103,7 +103,7 @@ impl<'a> Connection { mac.sign(packet.data(), self.seq.0, sig_cmp.as_mut_slice()); if sig != sig_cmp { - return Err(ConnectionError::IntegrityError); + return Err(ConnectionError::Integrity); } } @@ -119,7 +119,7 @@ impl<'a> Connection { -> io::Result<()> { debug!("Sending packet {}: {:?}", self.seq.1, packet); - let packet = packet.to_raw()?; + let packet = packet.into_raw()?; if let Some((_, ref mut s2c)) = self.encryption { let mut encrypted = vec![0; packet.data().len()]; @@ -177,18 +177,18 @@ impl<'a> Connection { } fn generate_key(&mut self, id: &[u8], len: usize) -> Result> { - use self::ConnectionError::KeyGenerationError; + use self::ConnectionError::KeyGeneration; - let kex = self.key_exchange.take().ok_or(KeyGenerationError)?; + let kex = self.key_exchange.take().ok_or(KeyGeneration)?; let key = kex.hash( &[ - kex.shared_secret().ok_or(KeyGenerationError)?, - kex.exchange_hash().ok_or(KeyGenerationError)?, + kex.shared_secret().ok_or(KeyGeneration)?, + kex.exchange_hash().ok_or(KeyGeneration)?, id, self.session_id .as_ref() - .ok_or(KeyGenerationError)? + .ok_or(KeyGeneration)? .as_slice(), ], ); @@ -211,7 +211,7 @@ impl<'a> Connection { MessageType::KeyExchange(_) => self.key_exchange(packet), _ => { error!("Unhandled packet: {:?}", packet); - Err(ConnectionError::ProtocolError) + Err(ConnectionError::Protocol) } } } @@ -435,7 +435,7 @@ impl<'a> Connection { fn key_exchange(&mut self, packet: Packet) -> Result> { let mut kex = self.key_exchange.take().ok_or( - ConnectionError::KeyExchangeError, + ConnectionError::KeyExchange, )?; let result = match kex.process(self, packet) @@ -452,7 +452,7 @@ impl<'a> Connection { Ok(Some(packet)) } KexResult::Ok(packet) => Ok(Some(packet)), - KexResult::Error => Err(ConnectionError::KeyExchangeError), + KexResult::Error => Err(ConnectionError::KeyExchange), }; diff --git a/src/error.rs b/src/error.rs index 228766f..a8025aa 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,12 +5,12 @@ pub type ConnectionResult = Result; #[derive(Debug)] pub enum ConnectionError { - IoError(io::Error), - ProtocolError, - NegotiationError, - KeyExchangeError, - KeyGenerationError, - IntegrityError, + Io(io::Error), + Protocol, + Negotiation, + KeyExchange, + KeyGeneration, + Integrity, } impl fmt::Display for ConnectionError { @@ -18,18 +18,18 @@ impl fmt::Display for ConnectionError { use self::ConnectionError::*; write!(f, "connection error: {}", (match &self { - IoError(err) => format!("io error: {}", err), - ProtocolError => "protocol error".to_owned(), - NegotiationError => "negotiation error".to_owned(), - KeyExchangeError => "key exchange error".to_owned(), - KeyGenerationError => "key generation error".to_owned(), - IntegrityError => "integrity error".to_owned(), + Io(err) => format!("io error: {}", err), + Protocol => "protocol error".to_owned(), + Negotiation => "negotiation error".to_owned(), + KeyExchange => "key exchange error".to_owned(), + KeyGeneration => "key generation error".to_owned(), + Integrity => "integrity error".to_owned(), })) } } impl From for ConnectionError { fn from(err: io::Error) -> ConnectionError { - ConnectionError::IoError(err) + ConnectionError::Io(err) } } diff --git a/src/mac/hmac.rs b/src/mac/hmac.rs index c662fa5..58a2567 100644 --- a/src/mac/hmac.rs +++ b/src/mac/hmac.rs @@ -25,7 +25,7 @@ impl MacAlgorithm for Hmac { ((seq & 0xff000000) >> 24) as u8, ((seq & 0x00ff0000) >> 16) as u8, ((seq & 0x0000ff00) >> 8) as u8, - ((seq & 0x000000ff)) as u8, + (seq & 0x000000ff) as u8, ]; self.hmac.input(sequence); diff --git a/src/packet.rs b/src/packet.rs index 516f68b..b1aa6af 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -84,7 +84,7 @@ impl Packet { } } - pub fn to_raw(self) -> Result { + pub fn into_raw(self) -> Result { match self { Packet::Raw(_, _) => Ok(self), @@ -134,10 +134,10 @@ impl Packet { impl Write for Packet { fn write(&mut self, buf: &[u8]) -> Result { - match self + match *self { - &mut Packet::Payload(ref mut payload) => payload.write(buf), - &mut Packet::Raw(ref mut data, ref mut payload_len) => { + Packet::Payload(ref mut payload) => payload.write(buf), + Packet::Raw(ref mut data, ref mut payload_len) => { let count = data.write(buf)?; *payload_len += count; Ok(count) diff --git a/src/public_key/mod.rs b/src/public_key/mod.rs index f8686b7..04f5ffb 100644 --- a/src/public_key/mod.rs +++ b/src/public_key/mod.rs @@ -1,11 +1,10 @@ use std::io::{self, Read, Write}; -// mod rsa; mod ed25519; - -// pub use self::rsa::RSA; +// mod rsa; pub use self::ed25519::ED25519; +// pub use self::rsa::RSA; pub trait KeyPair: Sync + Send { fn system(&self) -> &'static CryptoSystem; diff --git a/src/server.rs b/src/server.rs index b6695f4..f46b362 100644 --- a/src/server.rs +++ b/src/server.rs @@ -42,7 +42,5 @@ impl Server { } }); } - - Ok(()) } }