From 0d72cdc878fbc7a5b80d41680e94889646ecd8b2 Mon Sep 17 00:00:00 2001 From: Vlad Semenov Date: Tue, 7 Mar 2023 23:05:15 +0300 Subject: [PATCH 1/3] serde no_std compatibility --- Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 57bc2da..4aab93d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ sha2 = { version = "0.10", default-features = false } merlin = { version = "3", default-features = false, optional = true } rand_core = { version = "0.6.4", default-features = false, optional = true } serde = { version = "1.0", default-features = false, optional = true } -serde_bytes = { version = "0.11", optional = true } +serde_bytes = { version = "0.11", default-features = false, optional = true } zeroize = { version = "1.5", default-features = false, optional = true } [dev-dependencies] @@ -46,7 +46,7 @@ criterion = { version = "0.4", features = ["html_reports"] } hex-literal = "0.3" rand = "0.8" rand_core = { version = "0.6.4", default-features = false } -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", default-features = false, features = ["derive"] } toml = { version = "0.5" } [[bench]] @@ -56,8 +56,8 @@ required-features = ["rand_core"] [features] default = ["fast", "std", "zeroize"] -alloc = ["curve25519-dalek/alloc", "ed25519/alloc", "serde?/alloc", "zeroize/alloc"] -std = ["alloc", "ed25519/std", "serde?/std", "sha2/std"] +alloc = ["curve25519-dalek/alloc", "ed25519/alloc", "serde?/alloc", "serde_bytes?/alloc", "zeroize/alloc"] +std = ["alloc", "ed25519/std", "serde?/std", "serde_bytes?/std", "sha2/std"] asm = ["sha2/asm"] batch = ["alloc", "merlin", "rand_core"] @@ -68,5 +68,5 @@ legacy_compatibility = [] pkcs8 = ["ed25519/pkcs8"] pem = ["alloc", "ed25519/pem", "pkcs8"] rand_core = ["dep:rand_core"] -serde = ["dep:serde", "serde_bytes", "ed25519/serde"] +serde = ["dep:serde", "ed25519/serde", "serde_bytes"] zeroize = ["dep:zeroize", "curve25519-dalek/zeroize"] From bf7aacdc4bfe74ca3923f52c2335ce123be466b3 Mon Sep 17 00:00:00 2001 From: Vlad Semenov Date: Wed, 8 Mar 2023 01:23:43 +0300 Subject: [PATCH 2/3] fixed cfg feature serde --- src/signing.rs | 6 +++--- src/verifying.rs | 6 +++--- tests/ed25519.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/signing.rs b/src/signing.rs index 28f7346..c31cbf8 100644 --- a/src/signing.rs +++ b/src/signing.rs @@ -19,7 +19,7 @@ use rand_core::CryptoRngCore; use serde::de::Error as SerdeError; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde_bytes::{ByteBuf as SerdeByteBuf, Bytes as SerdeBytes}; use sha2::Sha512; @@ -628,7 +628,7 @@ impl TryFrom> for SigningKey { } } -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] impl Serialize for SigningKey { fn serialize(&self, serializer: S) -> Result where @@ -638,7 +638,7 @@ impl Serialize for SigningKey { } } -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] impl<'d> Deserialize<'d> for SigningKey { fn deserialize(deserializer: D) -> Result where diff --git a/src/verifying.rs b/src/verifying.rs index 1ea9332..f7a6ffc 100644 --- a/src/verifying.rs +++ b/src/verifying.rs @@ -31,7 +31,7 @@ use ed25519::pkcs8; use serde::de::Error as SerdeError; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde_bytes::{ByteBuf as SerdeByteBuf, Bytes as SerdeBytes}; #[cfg(feature = "digest")] @@ -536,7 +536,7 @@ impl TryFrom> for VerifyingKey { } } -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] impl Serialize for VerifyingKey { fn serialize(&self, serializer: S) -> Result where @@ -546,7 +546,7 @@ impl Serialize for VerifyingKey { } } -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] impl<'d> Deserialize<'d> for VerifyingKey { fn deserialize(deserializer: D) -> Result where diff --git a/tests/ed25519.rs b/tests/ed25519.rs index a3a7ebc..fb065cf 100644 --- a/tests/ed25519.rs +++ b/tests/ed25519.rs @@ -468,14 +468,14 @@ mod integrations { } } -#[cfg(all(test, feature = "serde"))] +#[cfg(all(test, feature = "serde", any(feature = "alloc", feature = "std")))] #[derive(Debug, serde::Serialize, serde::Deserialize)] #[serde(crate = "serde")] struct Demo { signing_key: SigningKey, } -#[cfg(all(test, feature = "serde"))] +#[cfg(all(test, feature = "serde", any(feature = "alloc", feature = "std")))] mod serialisation { use super::*; From f709b595befcc10e38bb5e23b9ff05df03e7f1db Mon Sep 17 00:00:00 2001 From: Vlad Semenov Date: Wed, 8 Mar 2023 08:15:38 +0300 Subject: [PATCH 3/3] fix cfg serde for other imports --- src/signing.rs | 4 ++-- src/verifying.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/signing.rs b/src/signing.rs index c31cbf8..1c8628c 100644 --- a/src/signing.rs +++ b/src/signing.rs @@ -15,9 +15,9 @@ use ed25519::pkcs8; #[cfg(any(test, feature = "rand_core"))] use rand_core::CryptoRngCore; -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde::de::Error as SerdeError; -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde_bytes::{ByteBuf as SerdeByteBuf, Bytes as SerdeBytes}; diff --git a/src/verifying.rs b/src/verifying.rs index f7a6ffc..4d67f00 100644 --- a/src/verifying.rs +++ b/src/verifying.rs @@ -27,9 +27,9 @@ use sha2::Sha512; #[cfg(feature = "pkcs8")] use ed25519::pkcs8; -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde::de::Error as SerdeError; -#[cfg(feature = "serde")] +#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] use serde_bytes::{ByteBuf as SerdeByteBuf, Bytes as SerdeBytes};