From 5332887e9db7ef79a7a4e724903dcac2df6e9ddc Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 24 Nov 2023 19:37:28 +0100 Subject: [PATCH] hpke-rs-crypto: make serde opt-in --- traits/Cargo.toml | 5 ++++- traits/src/types.rs | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/traits/Cargo.toml b/traits/Cargo.toml index e041095..19a720c 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -11,7 +11,10 @@ repository = "https://github.com/franziskuskiefer/hpke-rs" [dependencies] serde_json = { version = "1.0" } -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive"], optional = true } rand = { version = "0.8" } getrandom = { version = "0.2", features = ["js"] } tls_codec = { version = "0.4.0", features = ["derive"] } + +[features] +serde = ["dep:serde"] diff --git a/traits/src/types.rs b/traits/src/types.rs index 131e2cc..5b48dc3 100644 --- a/traits/src/types.rs +++ b/traits/src/types.rs @@ -2,12 +2,14 @@ //! //! Algorithm definitions for the [`crate::HpkeCrypto`] trait. +#[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use crate::error; /// KEM Modes -#[derive(PartialEq, Copy, Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(PartialEq, Copy, Clone, Debug)] #[repr(u16)] pub enum KemAlgorithm { /// DH KEM on P256 @@ -70,7 +72,8 @@ impl KemAlgorithm { } } -#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[repr(u16)] /// AEAD types pub enum AeadAlgorithm { @@ -150,7 +153,8 @@ impl AeadAlgorithm { } } -#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[repr(u16)] /// KDF types /// Value are taken from the HPKE RFC (not published yet)