mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 15:22:18 +01:00
Fix (clippy): Several fixes
- Remove enum suffixes (`enum_variant_names`) - Match de-/referencing (`match_ref_pats`) - Unused lifetime parameter (`extra_unused_lifetimes`) - Rename `to_raw` to `into_raw` to match convention (`wrong_self_convention`) All remaining warnings are in regards to unused variables, methods, enum variants, fields, or unreachable patterns. Also, unit result error types (`Result<u8, ()>`) remain (`result_unit_err`).
This commit is contained in:
parent
086b65038d
commit
cedf6ce410
7 changed files with 68 additions and 71 deletions
|
|
@ -36,7 +36,7 @@ pub fn negotiate<A: PartialEq + Copy>(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",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ pub struct Connection {
|
|||
channels: BTreeMap<ChannelId, Channel>,
|
||||
}
|
||||
|
||||
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<Vec<u8>> {
|
||||
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<Option<Packet>> {
|
||||
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),
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
26
src/error.rs
26
src/error.rs
|
|
@ -5,12 +5,12 @@ pub type ConnectionResult<T> = Result<T, ConnectionError>;
|
|||
|
||||
#[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<io::Error> for ConnectionError {
|
||||
fn from(err: io::Error) -> ConnectionError {
|
||||
ConnectionError::IoError(err)
|
||||
ConnectionError::Io(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl Packet {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_raw(self) -> Result<Packet> {
|
||||
pub fn into_raw(self) -> Result<Packet> {
|
||||
match self
|
||||
{
|
||||
Packet::Raw(_, _) => Ok(self),
|
||||
|
|
@ -134,10 +134,10 @@ impl Packet {
|
|||
|
||||
impl Write for Packet {
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,5 @@ impl Server {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue