diff --git a/Cargo.lock b/Cargo.lock index f8654a07..aba6fcf9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -868,7 +868,6 @@ dependencies = [ "rand_core 0.6.4", "rmp-serde", "serde", - "serde_bytes", "serde_with 1.14.0", "sha2", "sha3", diff --git a/nucypher-core/Cargo.toml b/nucypher-core/Cargo.toml index 00c650c3..c8c80c7f 100644 --- a/nucypher-core/Cargo.toml +++ b/nucypher-core/Cargo.toml @@ -26,4 +26,3 @@ zeroize = { version="1.6.0", features = ["derive"] } rand_core = "0.6.4" rand_chacha = "0.3.1" rand = "0.8.5" -serde_bytes = "0.11.9" diff --git a/nucypher-core/src/dkg.rs b/nucypher-core/src/dkg.rs index 7aafe105..14951774 100644 --- a/nucypher-core/src/dkg.rs +++ b/nucypher-core/src/dkg.rs @@ -121,9 +121,8 @@ pub mod session { use rand::SeedableRng; use rand_chacha::ChaCha20Rng; use rand_core::{CryptoRng, OsRng, RngCore}; - use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde_bytes; + use umbral_pre::serde_bytes; use x25519_dalek::{PublicKey, SharedSecret, StaticSecret}; use crate::secret_box::{kdf, SecretBox}; @@ -194,12 +193,21 @@ pub mod session { write!(f, "SessionStaticKey: {}", hex::encode(&self.as_ref()[..8])) } } + impl Serialize for SessionStaticKey { fn serialize(&self, serializer: S) -> Result where S: Serializer, { - serde_bytes::serialize(&self.as_ref(), serializer) + serde_bytes::as_hex::serialize(self.0.as_bytes(), serializer) + } + } + + impl serde_bytes::TryFromBytes for SessionStaticKey { + type Error = core::array::TryFromSliceError; + fn try_from_bytes(bytes: &[u8]) -> Result { + let array: [u8; 32] = bytes.try_into()?; + Ok(SessionStaticKey(PublicKey::from(array))) } } @@ -208,12 +216,7 @@ pub mod session { where D: Deserializer<'a>, { - let slice: &[u8] = serde_bytes::deserialize(deserializer)?; - let array: [u8; 32] = slice.try_into().map_err(|_| { - let expected = "[u8; 32]"; - Error::invalid_length(slice.len(), &expected) - })?; - Ok(Self(PublicKey::from(array))) + serde_bytes::as_hex::deserialize(deserializer) } }