1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
use ring::signature;
use crate::encryption::PublicKey;
use crate::packet::Data;
use crate::SshError;

pub(crate) struct Ed25519;

impl PublicKey for Ed25519 {
    fn new() -> Self where Self: Sized {
        Self
    }

    fn verify_signature(&self, ks: &[u8], message: &[u8], sig: &[u8]) -> Result<bool, SshError> {
        let mut data = Data(ks[4..].to_vec());
        data.get_u8s();
        let host_key = data.get_u8s();
        let pub_key =
            signature::UnparsedPublicKey::new(&signature::ED25519, host_key);
        Ok(pub_key.verify(message, sig).is_ok())
    }
}