Skip to content

Commit

Permalink
Added SshSig serializing/deserializing using serde
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroPanda123 committed Aug 10, 2024
1 parent 16d0fac commit 03e3d42
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ssh-key/src/sshsig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use crate::{PrivateKey, PublicKey};

type Version = u32;

#[cfg(feature = "serde")]
use serde::{de, ser, Deserialize, Serialize};

/// `sshsig` provides a general-purpose signature format based on SSH keys and
/// wire formats.
///
Expand Down Expand Up @@ -346,3 +349,24 @@ impl Encode for SignedData<'_> {
Ok(())
}
}

#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for SshSig {
fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
where
D: de::Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
string.parse::<SshSig>().map_err(de::Error::custom)
}
}

#[cfg(feature = "serde")]
impl Serialize for SshSig {
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
S: ser::Serializer,
{
self.to_pem(LineEnding::LF).map_err(ser::Error::custom)?.serialize(serializer)
}
}

0 comments on commit 03e3d42

Please sign in to comment.