fix serialize for keypair
This commit is contained in:
		| @@ -1,5 +1,4 @@ | ||||
| mod blake3digest512; | ||||
| mod byte_array_types; | ||||
| mod dh_cache; | ||||
| mod envelope; | ||||
| mod receipt; | ||||
| @@ -13,7 +12,7 @@ pub mod tests; | ||||
| pub mod vld0; | ||||
|  | ||||
| pub use blake3digest512::*; | ||||
| pub use byte_array_types::*; | ||||
|  | ||||
| pub use crypto_system::*; | ||||
| pub use dh_cache::*; | ||||
| pub use envelope::*; | ||||
|   | ||||
| @@ -3,8 +3,7 @@ use super::*; | ||||
| #[derive( | ||||
|     Clone, | ||||
|     Copy, | ||||
|     Serialize, | ||||
|     Deserialize, | ||||
|     Default, | ||||
|     PartialOrd, | ||||
|     Ord, | ||||
|     PartialEq, | ||||
| @@ -87,3 +86,26 @@ impl TryFrom<&str> for KeyPair { | ||||
|         Self::try_decode(value) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl serde::Serialize for KeyPair { | ||||
|     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||||
|     where | ||||
|         S: serde::Serializer, | ||||
|     { | ||||
|         let s = self.encode(); | ||||
|         serde::Serialize::serialize(&s, serializer) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<'de> serde::Deserialize<'de> for KeyPair { | ||||
|     fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||||
|     where | ||||
|         D: serde::Deserializer<'de>, | ||||
|     { | ||||
|         let s = <String as serde::Deserialize>::deserialize(deserializer)?; | ||||
|         if s == "" { | ||||
|             return Ok(KeyPair::default()); | ||||
|         } | ||||
|         KeyPair::try_decode(s.as_str()).map_err(serde::de::Error::custom) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -41,10 +41,12 @@ pub fn common_crypto_kinds(a: &[CryptoKind], b: &[CryptoKind]) -> Vec<CryptoKind | ||||
|     out | ||||
| } | ||||
|  | ||||
| mod byte_array_types; | ||||
| mod crypto_typed; | ||||
| mod crypto_typed_group; | ||||
| mod keypair; | ||||
|  | ||||
| pub use byte_array_types::*; | ||||
| pub use crypto_typed::*; | ||||
| pub use crypto_typed_group::*; | ||||
| pub use keypair::*; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user