mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 18:42:18 +01:00
Fix (clippy): Replace unit result error types with error types (result_unit_err)
e.g., `Result<Vec<u8>, ()>` All remaining warnings are in regards to unused variables, methods, enum variants, fields, or unreachable patterns.
This commit is contained in:
parent
cedf6ce410
commit
c68ba22265
2 changed files with 34 additions and 12 deletions
|
|
@ -4,7 +4,9 @@ use std::io::ErrorKind::InvalidData;
|
||||||
use crypto::ed25519;
|
use crypto::ed25519;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
|
||||||
use crate::public_key::{CryptoSystem, KeyPair};
|
use crate::public_key::{
|
||||||
|
CryptoSystem, KeyPair, KeyPairIdValidationError, SigningError
|
||||||
|
};
|
||||||
|
|
||||||
pub static ED25519: CryptoSystem = CryptoSystem {
|
pub static ED25519: CryptoSystem = CryptoSystem {
|
||||||
id: "ed25519",
|
id: "ed25519",
|
||||||
|
|
@ -84,32 +86,34 @@ impl KeyPair for Ed25519KeyPair {
|
||||||
self.private.is_some()
|
self.private.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool, ()> {
|
fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool, KeyPairIdValidationError> {
|
||||||
use crate::packet::ReadPacketExt;
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
use crate::packet::ReadPacketExt;
|
||||||
|
|
||||||
|
const EXPECTED_ID: &[u8] = b"ssh-ed25519";
|
||||||
|
|
||||||
let mut reader = Cursor::new(signature);
|
let mut reader = Cursor::new(signature);
|
||||||
let id = reader.read_string().unwrap_or_default();
|
let received_id = reader.read_string().unwrap_or_default();
|
||||||
|
|
||||||
if id == b"ssh-ed25519" {
|
if received_id == EXPECTED_ID {
|
||||||
if let Ok(sig) = reader.read_string() {
|
if let Ok(sig) = reader.read_string() {
|
||||||
return Ok(ed25519::verify(data, &self.public, sig.as_slice()));
|
return Ok(ed25519::verify(data, &self.public, sig.as_slice()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(())
|
Err(KeyPairIdValidationError {received_id, expected_id: EXPECTED_ID })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign(&self, data: &[u8]) -> Result<Vec<u8>, ()> {
|
fn sign(&self, data: &[u8]) -> Result<Vec<u8>, SigningError> {
|
||||||
use crate::packet::WritePacketExt;
|
use crate::packet::WritePacketExt;
|
||||||
if let Some(private_key) = self.private {
|
if let Some(private_key) = self.private {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
let sig = ed25519::signature(data, &private_key);
|
let sig = ed25519::signature(data, &private_key);
|
||||||
result.write_string("ssh-ed25519").or(Err(()))?;
|
result.write_string("ssh-ed25519")?;
|
||||||
result.write_bytes(&sig).or(Err(()))?;
|
result.write_bytes(&sig)?;
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Err(())
|
Err(SigningError::NoPrivateKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ pub trait KeyPair: Sync + Send {
|
||||||
|
|
||||||
fn has_private(&self) -> bool;
|
fn has_private(&self) -> bool;
|
||||||
|
|
||||||
fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool, ()>;
|
fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool, KeyPairIdValidationError>;
|
||||||
fn sign(&self, data: &[u8]) -> Result<Vec<u8>, ()>;
|
fn sign(&self, data: &[u8]) -> Result<Vec<u8>, SigningError>;
|
||||||
|
|
||||||
fn write_public(&self, w: &mut dyn Write) -> io::Result<()>;
|
fn write_public(&self, w: &mut dyn Write) -> io::Result<()>;
|
||||||
fn export(&self, w: &mut dyn Write) -> io::Result<()>;
|
fn export(&self, w: &mut dyn Write) -> io::Result<()>;
|
||||||
|
|
@ -24,3 +24,21 @@ pub struct CryptoSystem {
|
||||||
pub import: fn(r: &mut dyn Read) -> io::Result<Box<dyn KeyPair>>,
|
pub import: fn(r: &mut dyn Read) -> io::Result<Box<dyn KeyPair>>,
|
||||||
pub read_public: fn(r: &mut dyn Read) -> io::Result<Box<dyn KeyPair>>,
|
pub read_public: fn(r: &mut dyn Read) -> io::Result<Box<dyn KeyPair>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum SigningError {
|
||||||
|
NoPrivateKey,
|
||||||
|
Io(io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<io::Error> for SigningError {
|
||||||
|
fn from(value: io::Error) -> Self {
|
||||||
|
SigningError::Io(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct KeyPairIdValidationError<'a> {
|
||||||
|
pub expected_id: &'a [u8],
|
||||||
|
pub received_id: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue