1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 15:02:18 +01:00

Fix (lints): Run clippy automatic fixes

This commit is contained in:
Laurenz 2024-09-26 14:19:25 +02:00
parent d25d37a751
commit 086b65038d
Signed by: C0ffeeCode
SSH key fingerprint: SHA256:jnEltBNftC3wUZESLSMvM9zVPOkkevGRzqqoW2k2ORI
10 changed files with 50 additions and 53 deletions

View file

@ -3,7 +3,6 @@ extern crate log;
use std::env;
use std::fs::File;
use std::io::{self, Write};
use std::process;
use std::str::FromStr;
@ -21,8 +20,7 @@ impl log::Log for StdErrLogger {
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
writeln!(io::stderr(), "{} - {}", record.level(), record.args())
.unwrap();
eprintln!("{} - {}", record.level(), record.args());
}
}
@ -40,8 +38,7 @@ pub fn main() {
);
if let Some(ref err) = key_pair.as_ref().err() {
writeln!(io::stderr(), "sshd: failed to open server.key: {}", err)
.unwrap();
eprintln!("sshd: failed to open server.key: {}", err);
process::exit(1);
}
@ -82,7 +79,7 @@ pub fn main() {
let server = Server::with_config(config);
if let Err(err) = server.run() {
writeln!(io::stderr(), "sshd: {}", err).unwrap();
eprintln!("sshd: {}", err);
process::exit(1);
}
}

View file

@ -42,14 +42,14 @@ impl Channel {
max_packet_size: u32
) -> Channel {
Channel {
id: id,
peer_id: peer_id,
id,
peer_id,
process: None,
master: None,
pty: None,
window_size: peer_window_size,
peer_window_size: peer_window_size,
max_packet_size: max_packet_size,
peer_window_size,
max_packet_size,
read_thread: None,
}
}
@ -118,25 +118,25 @@ impl Channel {
self.master = Some(unsafe { File::from_raw_fd(master_fd) });
}
ChannelRequest::Shell => {
if let Some(&(_, ref tty_path)) = self.pty.as_ref() {
if let Some((_, tty_path)) = self.pty.as_ref() {
let stdin = OpenOptions::new()
.read(true)
.write(true)
.open(&tty_path)
.open(tty_path)
.unwrap()
.into_raw_fd();
let stdout = OpenOptions::new()
.read(true)
.write(true)
.open(&tty_path)
.open(tty_path)
.unwrap()
.into_raw_fd();
let stderr = OpenOptions::new()
.read(true)
.write(true)
.open(&tty_path)
.open(tty_path)
.unwrap()
.into_raw_fd();
@ -145,7 +145,7 @@ impl Channel {
.stdin(Stdio::from_raw_fd(stdin))
.stdout(Stdio::from_raw_fd(stdout))
.stderr(Stdio::from_raw_fd(stderr))
.pre_exec(|| sys::before_exec())
.pre_exec(sys::before_exec)
}
.spawn()
.unwrap();

View file

@ -49,7 +49,7 @@ pub struct Connection {
impl<'a> Connection {
pub fn new(conn_type: ConnectionType) -> Connection {
Connection {
conn_type: conn_type,
conn_type,
hash_data: HashData::default(),
state: ConnectionState::Initial,
key_exchange: None,
@ -147,8 +147,8 @@ impl<'a> Connection {
let id = format!("SSH-2.0-RedoxSSH_{}", env!("CARGO_PKG_VERSION"));
info!("Identifying as {:?}", id);
stream.write(id.as_bytes())?;
stream.write(b"\r\n")?;
stream.write_all(id.as_bytes())?;
stream.write_all(b"\r\n")?;
stream.flush()?;
self.hash_data.server_id = Some(id);
@ -246,7 +246,7 @@ impl<'a> Connection {
trace!(
"Service Request {:?}",
::std::str::from_utf8(&name.as_slice()).unwrap()
::std::str::from_utf8(name.as_slice()).unwrap()
);
let mut res = Packet::new(MessageType::ServiceAccept);
@ -262,7 +262,7 @@ impl<'a> Connection {
let method = reader.read_utf8()?;
let success = if method == "password" {
assert!(reader.read_bool()? == false);
assert!(!(reader.read_bool()?));
let pass = reader.read_utf8()?;
pass == "hunter2"
}
@ -406,7 +406,7 @@ impl<'a> Connection {
// Create a random 16 byte cookie
use rand::Rng;
let mut rng = rand::thread_rng();
let rng = rand::thread_rng();
let cookie: Vec<u8> = rng.sample_iter(Standard).take(16).collect();
let mut packet = Packet::new(MessageType::KexInit);

View file

@ -18,8 +18,8 @@ impl<'a> Decryptor<'a> {
pub fn new(encryption: &'a mut dyn Encryption, stream: &'a mut dyn Read)
-> Decryptor<'a> {
Decryptor {
encryption: encryption,
stream: stream,
encryption,
stream,
}
}
}

View file

@ -27,12 +27,12 @@ impl Curve25519 {
}
impl KeyExchange for Curve25519 {
fn shared_secret<'a>(&'a self) -> Option<&'a [u8]> {
fn shared_secret(&self) -> Option<&[u8]> {
self.shared_secret.as_ref().map(|x| x as &[u8])
}
fn exchange_hash<'a>(&'a self) -> Option<&'a [u8]> {
self.exchange_hash.as_ref().map(|x| x.as_slice())
fn exchange_hash(&self) -> Option<&[u8]> {
self.exchange_hash.as_deref()
}
fn hash(&self, data: &[&[u8]]) -> Vec<u8> {
@ -56,7 +56,7 @@ impl KeyExchange for Curve25519 {
let config = match &conn.conn_type
{
&ConnectionType::Server(ref config) => config.clone(),
ConnectionType::Server(config) => config.clone(),
_ => return KexResult::Error,
};

View file

@ -15,7 +15,7 @@ pub enum KexResult {
pub trait KeyExchange {
fn process(&mut self, conn: &mut Connection, packet: Packet) -> KexResult;
fn shared_secret<'a>(&'a self) -> Option<&'a [u8]>;
fn exchange_hash<'a>(&'a self) -> Option<&'a [u8]>;
fn shared_secret(&self) -> Option<&[u8]>;
fn exchange_hash(&self) -> Option<&[u8]>;
fn hash(&self, data: &[&[u8]]) -> Vec<u8>;
}

View file

@ -69,10 +69,10 @@ impl From<u8> for MessageType {
}
}
impl Into<u8> for MessageType {
fn into(self) -> u8 {
impl From<MessageType> for u8 {
fn from(val: MessageType) -> Self {
use self::MessageType::*;
match self
match val
{
Disconnect => 1,
Ignore => 2,

View file

@ -20,8 +20,8 @@ impl Packet {
pub fn msg_type(&self) -> MessageType {
match self
{
&Packet::Raw(ref data, _) => data[5],
&Packet::Payload(ref data) => data[0],
Packet::Raw(data, _) => data[5],
Packet::Payload(data) => data[0],
}.into()
}
@ -50,17 +50,17 @@ impl Packet {
pub fn write_to<W: io::Write>(&self, stream: &mut W) -> Result<()> {
match self
{
&Packet::Raw(ref data, _) => {
Packet::Raw(data, _) => {
stream.write_all(data)?;
stream.flush()
}
&Packet::Payload(ref payload) => {
Packet::Payload(payload) => {
let padding_len = self.padding_len();
let packet_len = payload.len() + padding_len + 1;
stream.write_u32::<BigEndian>(packet_len as u32)?;
stream.write_u8(padding_len as u8)?;
stream.write_all(&payload)?;
stream.write_all(payload)?;
stream.write_all(&[0u8; 255][..padding_len])?;
stream.flush()
@ -76,11 +76,11 @@ impl Packet {
}
}
pub fn data<'a>(&'a self) -> &'a [u8] {
pub fn data(&self) -> &[u8] {
match self
{
&Packet::Raw(ref data, _) => &data,
&Packet::Payload(ref payload) => &payload,
Packet::Raw(data, _) => data,
Packet::Payload(payload) => payload,
}
}
@ -96,13 +96,13 @@ impl Packet {
}
}
pub fn reader<'a>(&'a self) -> BufReader<&'a [u8]> {
pub fn reader(&self) -> BufReader<&[u8]> {
match self
{
&Packet::Raw(ref data, payload_len) => {
BufReader::new(&data.as_slice()[6..payload_len + 5])
}
&Packet::Payload(ref payload) => {
Packet::Payload(payload) => {
BufReader::new(&payload.as_slice()[1..])
}
}
@ -112,7 +112,7 @@ impl Packet {
match self
{
&Packet::Raw(_, payload_len) => payload_len,
&Packet::Payload(ref payload) => payload.len(),
Packet::Payload(payload) => payload.len(),
}
}
@ -163,7 +163,7 @@ pub trait ReadPacketExt: ReadBytesExt {
}
fn read_uint32(&mut self) -> Result<u32> {
Ok(self.read_u32::<BigEndian>()?)
self.read_u32::<BigEndian>()
}
fn read_bytes(&mut self, len: usize) -> Result<Vec<u8>> {
@ -189,7 +189,7 @@ pub trait ReadPacketExt: ReadBytesExt {
Ok(
string
.split(",")
.filter_map(|l| T::from_str(&l).ok())
.filter_map(|l| T::from_str(l).ok())
.collect(),
)
}
@ -231,20 +231,20 @@ pub trait WritePacketExt: WriteBytesExt {
}
fn write_uint32(&mut self, value: u32) -> Result<()> {
self.write_u32::<BigEndian>(value as u32)
self.write_u32::<BigEndian>(value)
}
fn write_list<T: ToString>(&mut self, list: &[T]) -> Result<()> {
let mut string = String::new();
let mut iter = list.iter();
let iter = list.iter();
while let Some(item) = iter.next() {
for item in iter {
if !string.is_empty() {
string += ",";
}
string += &*item.to_string();
}
self.write_string(&*string)
self.write_string(&string)
}
}

View file

@ -53,7 +53,7 @@ impl Ed25519KeyPair {
r.read_exact(&mut private)?;
Ok(Box::new(Ed25519KeyPair {
public: public,
public,
private: Some(private),
}))
}
@ -70,7 +70,7 @@ impl Ed25519KeyPair {
Ok(Box::new(Ed25519KeyPair {
private: None,
public: public,
public,
}))
}
}
@ -89,7 +89,7 @@ impl KeyPair for Ed25519KeyPair {
use std::io::Cursor;
let mut reader = Cursor::new(signature);
let id = reader.read_string().unwrap_or(vec![]);
let id = reader.read_string().unwrap_or_default();
if id == b"ssh-ed25519" {
if let Ok(sig) = reader.read_string() {

View file

@ -3,7 +3,7 @@ extern crate rand;
use std::io::Cursor;
use rand::{Rng, RngCore};
use rand::RngCore;
use ssh::public_key::{self, CryptoSystem, KeyPair};
fn test_export_import(keypair: &Box<dyn KeyPair>) -> Box<dyn KeyPair> {