use crate::error;
use crate::wire;
use ed25519_dalek::{SigningKey, VerifyingKey};
use embedded_io_async::{ErrorType, Read, Write};
use rand::{CryptoRng, Rng};
#[derive(Debug)]
pub enum SecretKey {
Ed25519 { secret_key: SigningKey },
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PublicKey {
Ed25519 { public_key: VerifyingKey },
}
impl<'a> From<&'a PublicKey> for wire::PublicKey<'a> {
fn from(value: &'a PublicKey) -> Self {
match value {
PublicKey::Ed25519 { public_key } => Self::Ed25519 {
public_key: public_key.as_bytes(),
},
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AuthMethod {
None,
PublicKey(PublicKey),
}
#[derive(Clone, Copy, Debug)]
pub enum Request<T> {
Shell,
Exec(T),
}
pub trait Behavior {
type Stream: Read + Write;
fn stream(&mut self) -> &mut Self::Stream;
type Random: CryptoRng + Rng;
fn random(&mut self) -> &mut Self::Random;
fn host_secret_key(&self) -> &SecretKey;
fn server_id(&self) -> &'static str {
"SSH-2.0-zssh_0.2.0"
}
fn allow_user(&mut self, username: &str, auth_method: &AuthMethod) -> Option<Self::User>;
type User: Clone;
fn allow_shell(&self) -> bool {
false
}
type Command: Clone;
fn parse_command(&mut self, command: &str) -> Self::Command;
}
pub type TransportError<T> = error::Error<<<T as Behavior>::Stream as ErrorType>::Error>;