1use ssh_key::PublicKey;
4
5#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
7pub enum SshKeyError {
8 #[error("Malformed or invalid OpenSSH public key: {0}")]
9 InvalidFormat(String),
10
11 #[error("Unsupported key type: expected ssh-ed25519")]
12 UnsupportedKeyType,
13}
14
15pub fn openssh_pub_to_raw_ed25519(openssh_pub: &str) -> Result<[u8; 32], SshKeyError> {
26 let public_key = PublicKey::from_openssh(openssh_pub)
27 .map_err(|e| SshKeyError::InvalidFormat(e.to_string()))?;
28
29 let ed25519_key = public_key
30 .key_data()
31 .ed25519()
32 .ok_or(SshKeyError::UnsupportedKeyType)?;
33
34 Ok(ed25519_key.0)
35}