|
1 | | -use std::str::FromStr as _; |
| 1 | +use ssh_encoding::{Decode, Encode, Reader}; |
| 2 | +use ssh_key::{public::KeyData, Certificate}; |
2 | 3 |
|
3 | | -use ssh_encoding::{CheckedSum as _, Decode, Encode, Reader}; |
4 | | -use ssh_key::{public::KeyData, Algorithm, Certificate, PublicKey}; |
5 | | - |
6 | | -use crate::proto::{Error, Result}; |
| 4 | +use crate::proto::Error; |
7 | 5 |
|
8 | 6 | #[derive(Debug, PartialEq, Eq, Clone)] |
| 7 | +/// Represents a public credential. |
9 | 8 | pub enum CertKeyData { |
| 9 | + /// Plain public key. |
10 | 10 | Key(KeyData), |
| 11 | + /// Signed public key. |
11 | 12 | Cert(Certificate), |
12 | 13 | } |
13 | 14 |
|
| 15 | +impl CertKeyData { |
| 16 | + /// Returns a reference to the [KeyData]. |
| 17 | + pub fn key_data(&self) -> &KeyData { |
| 18 | + match self { |
| 19 | + Self::Key(key) => key, |
| 20 | + Self::Cert(cert) => cert.public_key(), |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
14 | 25 | impl Decode for CertKeyData { |
15 | 26 | type Error = Error; |
16 | 27 |
|
17 | 28 | fn decode(reader: &mut impl Reader) -> core::result::Result<Self, Self::Error> { |
18 | | - let alg = String::decode(reader)?; |
19 | | - let cert_alg = Algorithm::new_certificate(&alg); |
20 | | - |
21 | | - if let Ok(algorithm) = cert_alg { |
22 | | - let certificate = Certificate::decode_as(algorithm.clone(), reader)?; |
23 | | - Ok(Self::Cert(certificate)) |
24 | | - } else { |
25 | | - let algorithm = Algorithm::from_str(&alg).map_err(ssh_encoding::Error::from)?; |
26 | | - let pubkey = KeyData::decode_as(reader, algorithm)?; |
27 | | - Ok(Self::Key(pubkey)) |
28 | | - } |
| 29 | + // TODO: implement parsing certificates |
| 30 | + Ok(Self::Key(KeyData::decode(reader)?)) |
29 | 31 | } |
30 | 32 | } |
31 | 33 |
|
|
0 commit comments