Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh-key: Add Certificate::decode_as and expose KeyData::decode_as #233

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions ssh-key/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,9 @@ impl Certificate {
self.reserved.encode(writer)?;
self.signature_key.encode_prefixed(writer)
}
}

impl Decode for Certificate {
type Error = Error;

fn decode(reader: &mut impl Reader) -> Result<Self> {
let algorithm = Algorithm::new_certificate(&String::decode(reader)?)?;

/// Decode [`Certificate`] for the specified algorithm.
pub fn decode_as(reader: &mut impl Reader, algorithm: Algorithm) -> Result<Self> {
Ok(Self {
nonce: Vec::decode(reader)?,
public_key: KeyData::decode_as(reader, algorithm)?,
Expand All @@ -482,6 +477,15 @@ impl Decode for Certificate {
}
}

impl Decode for Certificate {
type Error = Error;

fn decode(reader: &mut impl Reader) -> Result<Self> {
let algorithm = Algorithm::new_certificate(&String::decode(reader)?)?;
Self::decode_as(reader, algorithm)
}
}

impl Encode for Certificate {
fn encoded_len(&self) -> encoding::Result<usize> {
[
Expand Down
2 changes: 1 addition & 1 deletion ssh-key/src/public/key_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl KeyData {
}

/// Decode [`KeyData`] for the specified algorithm.
pub(crate) fn decode_as(reader: &mut impl Reader, algorithm: Algorithm) -> Result<Self> {
pub fn decode_as(reader: &mut impl Reader, algorithm: Algorithm) -> Result<Self> {
match algorithm {
#[cfg(feature = "alloc")]
Algorithm::Dsa => DsaPublicKey::decode(reader).map(Self::Dsa),
Expand Down
Loading