ssh/algorithm/public_key/
mod.rs

1use crate::SshError;
2
3#[cfg(feature = "deprecated-dss-sha1")]
4mod dss;
5mod ed25519;
6mod rsa;
7
8#[cfg(feature = "deprecated-dss-sha1")]
9use self::dss::DssSha1;
10#[cfg(feature = "deprecated-rsa-sha1")]
11use self::rsa::RsaSha1;
12use self::rsa::RsaSha256;
13use self::rsa::RsaSha512;
14use super::PubKey;
15use ed25519::Ed25519;
16
17/// # Public Key Algorithms
18///
19/// <https://www.rfc-editor.org/rfc/rfc4253#section-6.6>
20
21pub(crate) trait PublicKey: Send + Sync {
22    fn new() -> Self
23    where
24        Self: Sized;
25    fn verify_signature(&self, ks: &[u8], message: &[u8], sig: &[u8]) -> Result<bool, SshError>;
26}
27
28pub(crate) fn from(s: &PubKey) -> Box<dyn PublicKey> {
29    match s {
30        PubKey::SshEd25519 => Box::new(Ed25519::new()),
31        #[cfg(feature = "deprecated-rsa-sha1")]
32        PubKey::SshRsa => Box::new(RsaSha1::new()),
33        PubKey::RsaSha2_256 => Box::new(RsaSha256::new()),
34        PubKey::RsaSha2_512 => Box::new(RsaSha512::new()),
35        #[cfg(feature = "deprecated-dss-sha1")]
36        PubKey::SshDss => Box::new(DssSha1::new()),
37    }
38}