1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 17:02:19 +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:
Laurenz 2024-09-26 16:04:11 +02:00
parent 086b65038d
commit cedf6ce410
Signed by: C0ffeeCode
SSH key fingerprint: SHA256:jnEltBNftC3wUZESLSMvM9zVPOkkevGRzqqoW2k2ORI
7 changed files with 68 additions and 71 deletions

View file

@ -36,7 +36,7 @@ pub fn negotiate<A: PartialEq + Copy>(server: &[A], client: &[A])
return Ok(*algorithm); return Ok(*algorithm);
} }
} }
Err(ConnectionError::NegotiationError) Err(ConnectionError::Negotiation)
} }
#[derive(Clone, Copy, PartialEq, Debug)] #[derive(Clone, Copy, PartialEq, Debug)]
@ -99,19 +99,19 @@ impl FromStr for KeyExchangeAlgorithm {
impl fmt::Display for KeyExchangeAlgorithm { impl fmt::Display for KeyExchangeAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::KeyExchangeAlgorithm::*; use self::KeyExchangeAlgorithm::*;
f.write_str(match self f.write_str(match *self
{ {
&CURVE25519_SHA256 => "curve25519-sha256", CURVE25519_SHA256 => "curve25519-sha256",
&ECDH_SHA2_NISTP256 => "ecdh-sha2-nistp256", ECDH_SHA2_NISTP256 => "ecdh-sha2-nistp256",
&ECDH_SHA2_NISTP384 => "ecdh-sha2-nistp384", ECDH_SHA2_NISTP384 => "ecdh-sha2-nistp384",
&ECDH_SHA2_NISTP521 => "ecdh-sha2-nistp521", ECDH_SHA2_NISTP521 => "ecdh-sha2-nistp521",
&DH_GROUP_EXCHANGE_SHA256 => "diffie-hellman-group-exchange-sha256", DH_GROUP_EXCHANGE_SHA256 => "diffie-hellman-group-exchange-sha256",
&DH_GROUP_EXCHANGE_SHA1 => "diffie-hellman-group-exchange-sha1", DH_GROUP_EXCHANGE_SHA1 => "diffie-hellman-group-exchange-sha1",
&DH_GROUP16_SHA512 => "diffie-hellman-group16-sha512", DH_GROUP16_SHA512 => "diffie-hellman-group16-sha512",
&DH_GROUP18_SHA512 => "diffie-hellman-group18-sha512", DH_GROUP18_SHA512 => "diffie-hellman-group18-sha512",
&DH_GROUP14_SHA256 => "diffie-hellman-group14-sha256", DH_GROUP14_SHA256 => "diffie-hellman-group14-sha256",
&DH_GROUP14_SHA1 => "diffie-hellman-group14-sha1", DH_GROUP14_SHA1 => "diffie-hellman-group14-sha1",
&EXT_INFO_C => "ext-info-c", EXT_INFO_C => "ext-info-c",
}) })
} }
} }
@ -152,15 +152,15 @@ impl FromStr for PublicKeyAlgorithm {
impl fmt::Display for PublicKeyAlgorithm { impl fmt::Display for PublicKeyAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::PublicKeyAlgorithm::*; use self::PublicKeyAlgorithm::*;
f.write_str(match self f.write_str(match *self
{ {
&SSH_RSA => "ssh-rsa", SSH_RSA => "ssh-rsa",
&RSA_SHA2_256 => "rsa-sha2-256", RSA_SHA2_256 => "rsa-sha2-256",
&RSA_SHA2_512 => "rsa-sha2-512", RSA_SHA2_512 => "rsa-sha2-512",
&ECDSA_SHA2_NISTP256 => "ecdsa-sha2-nistp256", ECDSA_SHA2_NISTP256 => "ecdsa-sha2-nistp256",
&ECDSA_SHA2_NISTP384 => "ecdsa-sha2-nistp384", ECDSA_SHA2_NISTP384 => "ecdsa-sha2-nistp384",
&ECDSA_SHA2_NISTP521 => "ecdsa-sha2-nistp521", ECDSA_SHA2_NISTP521 => "ecdsa-sha2-nistp521",
&SSH_ED25519 => "ssh-ed25519", SSH_ED25519 => "ssh-ed25519",
}) })
} }
} }
@ -201,15 +201,15 @@ impl FromStr for EncryptionAlgorithm {
impl fmt::Display for EncryptionAlgorithm { impl fmt::Display for EncryptionAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::EncryptionAlgorithm::*; use self::EncryptionAlgorithm::*;
f.write_str(match self f.write_str(match *self
{ {
&AES128_CTR => "aes128-ctr", AES128_CTR => "aes128-ctr",
&AES128_CBC => "aes128-cbc", AES128_CBC => "aes128-cbc",
&AES192_CTR => "aes192-ctr", AES192_CTR => "aes192-ctr",
&AES192_CBC => "aes192-cbc", AES192_CBC => "aes192-cbc",
&AES256_CTR => "aes256-ctr", AES256_CTR => "aes256-ctr",
&AES256_CBC => "aes256-cbc", AES256_CBC => "aes256-cbc",
&EncryptionAlgorithm::None => "none", EncryptionAlgorithm::None => "none",
}) })
} }
} }
@ -244,12 +244,12 @@ impl FromStr for MacAlgorithm {
impl fmt::Display for MacAlgorithm { impl fmt::Display for MacAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::MacAlgorithm::*; use self::MacAlgorithm::*;
f.write_str(match self f.write_str(match *self
{ {
&HMAC_SHA1 => "hmac-sha1", HMAC_SHA1 => "hmac-sha1",
&HMAC_SHA2_256 => "hmac-sha2-256", HMAC_SHA2_256 => "hmac-sha2-256",
&HMAC_SHA2_512 => "hmac-sha2-512", HMAC_SHA2_512 => "hmac-sha2-512",
&MacAlgorithm::None => "none", MacAlgorithm::None => "none",
}) })
} }
} }
@ -277,10 +277,10 @@ impl FromStr for CompressionAlgorithm {
impl fmt::Display for CompressionAlgorithm { impl fmt::Display for CompressionAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match self f.write_str(match *self
{ {
&CompressionAlgorithm::Zlib => "zlib", CompressionAlgorithm::Zlib => "zlib",
&CompressionAlgorithm::None => "none", CompressionAlgorithm::None => "none",
}) })
} }
} }

View file

@ -46,7 +46,7 @@ pub struct Connection {
channels: BTreeMap<ChannelId, Channel>, channels: BTreeMap<ChannelId, Channel>,
} }
impl<'a> Connection { impl Connection {
pub fn new(conn_type: ConnectionType) -> Connection { pub fn new(conn_type: ConnectionType) -> Connection {
Connection { Connection {
conn_type, conn_type,
@ -103,7 +103,7 @@ impl<'a> Connection {
mac.sign(packet.data(), self.seq.0, sig_cmp.as_mut_slice()); mac.sign(packet.data(), self.seq.0, sig_cmp.as_mut_slice());
if sig != sig_cmp { if sig != sig_cmp {
return Err(ConnectionError::IntegrityError); return Err(ConnectionError::Integrity);
} }
} }
@ -119,7 +119,7 @@ impl<'a> Connection {
-> io::Result<()> { -> io::Result<()> {
debug!("Sending packet {}: {:?}", self.seq.1, packet); 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 { if let Some((_, ref mut s2c)) = self.encryption {
let mut encrypted = vec![0; packet.data().len()]; 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>> { 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( let key = kex.hash(
&[ &[
kex.shared_secret().ok_or(KeyGenerationError)?, kex.shared_secret().ok_or(KeyGeneration)?,
kex.exchange_hash().ok_or(KeyGenerationError)?, kex.exchange_hash().ok_or(KeyGeneration)?,
id, id,
self.session_id self.session_id
.as_ref() .as_ref()
.ok_or(KeyGenerationError)? .ok_or(KeyGeneration)?
.as_slice(), .as_slice(),
], ],
); );
@ -211,7 +211,7 @@ impl<'a> Connection {
MessageType::KeyExchange(_) => self.key_exchange(packet), MessageType::KeyExchange(_) => self.key_exchange(packet),
_ => { _ => {
error!("Unhandled packet: {:?}", 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>> { fn key_exchange(&mut self, packet: Packet) -> Result<Option<Packet>> {
let mut kex = self.key_exchange.take().ok_or( let mut kex = self.key_exchange.take().ok_or(
ConnectionError::KeyExchangeError, ConnectionError::KeyExchange,
)?; )?;
let result = match kex.process(self, packet) let result = match kex.process(self, packet)
@ -452,7 +452,7 @@ impl<'a> Connection {
Ok(Some(packet)) Ok(Some(packet))
} }
KexResult::Ok(packet) => Ok(Some(packet)), KexResult::Ok(packet) => Ok(Some(packet)),
KexResult::Error => Err(ConnectionError::KeyExchangeError), KexResult::Error => Err(ConnectionError::KeyExchange),
}; };

View file

@ -5,12 +5,12 @@ pub type ConnectionResult<T> = Result<T, ConnectionError>;
#[derive(Debug)] #[derive(Debug)]
pub enum ConnectionError { pub enum ConnectionError {
IoError(io::Error), Io(io::Error),
ProtocolError, Protocol,
NegotiationError, Negotiation,
KeyExchangeError, KeyExchange,
KeyGenerationError, KeyGeneration,
IntegrityError, Integrity,
} }
impl fmt::Display for ConnectionError { impl fmt::Display for ConnectionError {
@ -18,18 +18,18 @@ impl fmt::Display for ConnectionError {
use self::ConnectionError::*; use self::ConnectionError::*;
write!(f, "connection error: {}", (match &self write!(f, "connection error: {}", (match &self
{ {
IoError(err) => format!("io error: {}", err), Io(err) => format!("io error: {}", err),
ProtocolError => "protocol error".to_owned(), Protocol => "protocol error".to_owned(),
NegotiationError => "negotiation error".to_owned(), Negotiation => "negotiation error".to_owned(),
KeyExchangeError => "key exchange error".to_owned(), KeyExchange => "key exchange error".to_owned(),
KeyGenerationError => "key generation error".to_owned(), KeyGeneration => "key generation error".to_owned(),
IntegrityError => "integrity error".to_owned(), Integrity => "integrity error".to_owned(),
})) }))
} }
} }
impl From<io::Error> for ConnectionError { impl From<io::Error> for ConnectionError {
fn from(err: io::Error) -> ConnectionError { fn from(err: io::Error) -> ConnectionError {
ConnectionError::IoError(err) ConnectionError::Io(err)
} }
} }

View file

@ -25,7 +25,7 @@ impl MacAlgorithm for Hmac {
((seq & 0xff000000) >> 24) as u8, ((seq & 0xff000000) >> 24) as u8,
((seq & 0x00ff0000) >> 16) as u8, ((seq & 0x00ff0000) >> 16) as u8,
((seq & 0x0000ff00) >> 8) as u8, ((seq & 0x0000ff00) >> 8) as u8,
((seq & 0x000000ff)) as u8, (seq & 0x000000ff) as u8,
]; ];
self.hmac.input(sequence); self.hmac.input(sequence);

View file

@ -84,7 +84,7 @@ impl Packet {
} }
} }
pub fn to_raw(self) -> Result<Packet> { pub fn into_raw(self) -> Result<Packet> {
match self match self
{ {
Packet::Raw(_, _) => Ok(self), Packet::Raw(_, _) => Ok(self),
@ -134,10 +134,10 @@ impl Packet {
impl Write for Packet { impl Write for Packet {
fn write(&mut self, buf: &[u8]) -> Result<usize> { fn write(&mut self, buf: &[u8]) -> Result<usize> {
match self match *self
{ {
&mut Packet::Payload(ref mut payload) => payload.write(buf), Packet::Payload(ref mut payload) => payload.write(buf),
&mut Packet::Raw(ref mut data, ref mut payload_len) => { Packet::Raw(ref mut data, ref mut payload_len) => {
let count = data.write(buf)?; let count = data.write(buf)?;
*payload_len += count; *payload_len += count;
Ok(count) Ok(count)

View file

@ -1,11 +1,10 @@
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
// mod rsa;
mod ed25519; mod ed25519;
// mod rsa;
// pub use self::rsa::RSA;
pub use self::ed25519::ED25519; pub use self::ed25519::ED25519;
// pub use self::rsa::RSA;
pub trait KeyPair: Sync + Send { pub trait KeyPair: Sync + Send {
fn system(&self) -> &'static CryptoSystem; fn system(&self) -> &'static CryptoSystem;

View file

@ -42,7 +42,5 @@ impl Server {
} }
}); });
} }
Ok(())
} }
} }