Skip to content

Commit

Permalink
Remove serde support (#53)
Browse files Browse the repository at this point in the history
* Removed serde support

* Removed serde from CI

* Added `serde_impls` removal notice in README
  • Loading branch information
rozbb authored Nov 16, 2023
1 parent 57fce26 commit 362d7bc
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 253 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ jobs:
RUSTFLAGS: -D warnings -A dead_code -A unused_imports
run: cargo test --no-default-features --features="p384"

- name: Run cargo test with X25519 and serde impls enabled
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -D warnings -A dead_code -A unused_imports
run: cargo test --no-default-features --features="x25519,serde_impls"

- name: Run cargo test with all features enabled
env:
CARGO_INCREMENTAL: 0
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Pending

* Added `Serializable::write_exact` so serialization requires less stack space
* Removed all impls of `serde::{Serialize, Deserailize}` from crate

## [0.11.0] - 2023-10-11

Expand Down
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ default = ["alloc", "p256", "x25519"]
x25519 = ["dep:x25519-dalek"]
p384 = ["dep:p384"]
p256 = ["dep:p256"]
# Include serde Serialize/Deserialize impls for all relevant types
serde_impls = ["serde", "generic-array/serde"]
# Include allocating methods like open() and seal()
alloc = []
# Includes an implementation of `std::error::Error` for `HpkeError`. Also does what `alloc` does.
Expand All @@ -39,7 +37,6 @@ rand_core = { version = "0.6", default-features = false }
p256 = { version = "0.13", default-features = false, features = ["arithmetic", "ecdh"], optional = true}
p384 = { version = "0.13", default-features = false, features = ["arithmetic", "ecdh"], optional = true}
sha2 = { version = "0.10", default-features = false }
serde = { version = "1.0", default-features = false, optional = true }
subtle = { version = "2.5", default-features = false }
x25519-dalek = { version = "2", default-features = false, features = ["static_secrets"], optional = true }
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"] }
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Feature flag list:
* `x25519` - Enables X25519-based KEMs
* `p256` - Enables NIST P-256-based KEMs
* `p384` - Enables NIST P-384-based KEMs
* `serde_impls` - Includes implementations of `serde::Serialize` and `serde::Deserialize` for all `hpke::Serializable` and `hpke::Deserializable` types
* `std` - Includes an implementation of `std::error::Error` for `HpkeError`. Also does what `alloc` does.

For info on how to omit or include feature flags, see the [cargo docs on features](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#choosing-features).
Expand All @@ -61,6 +60,13 @@ Usage Examples

See the [client-server](examples/client_server.rs) example for an idea of how to use HPKE.

Breaking changes
----------------

### Breaking changes in v0.12

The `serde_impls` feature was removed. If you were using this and require backwards compatible serialization/deserialization, see the wiki page [here](https://github.com/rozbb/rust-hpke/wiki/Migrating-away-from-the-%60serde_impls%60-feature).

MSRV
----

Expand Down
28 changes: 0 additions & 28 deletions src/dhkex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use crate::{kdf::Kdf as KdfTrait, util::KemSuiteId, Deserializable, Serializable

use core::fmt::Debug;

#[cfg(feature = "serde_impls")]
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};

// This is the maximum value of all of Npk, Ndh, and Nenc. It's achieved by P-521 in RFC 9180 §7.1
// Table 2.
pub(crate) const MAX_PUBKEY_SIZE: usize = 133;
Expand All @@ -18,37 +15,12 @@ pub struct DhError;
/// way to generate keypairs, perform the Diffie-Hellman operation, and serialize/deserialize
/// pubkeys. This is built into a KEM in `kem/dhkem.rs`.
pub trait DhKeyExchange {
// Public and private keys need to implement serde::{Serialize, Deserialize} if the serde_impls
// feature is set. So double up all the definitions: one with serde and one without.

/// The key exchange's public key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(feature = "serde_impls")]
type PublicKey: Clone
+ Debug
+ PartialEq
+ Eq
+ Serializable
+ Deserializable
+ SerdeSerialize
+ for<'a> SerdeDeserialize<'a>;
/// The key exchange's public key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(not(feature = "serde_impls"))]
type PublicKey: Clone + Debug + PartialEq + Eq + Serializable + Deserializable;

/// The key exchange's private key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(feature = "serde_impls")]
type PrivateKey: Clone
+ Serializable
+ Deserializable
+ SerdeSerialize
+ for<'a> SerdeDeserialize<'a>;

/// The key exchange's private key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(not(feature = "serde_impls"))]
type PrivateKey: Clone + Serializable + Deserializable;

/// The result of a DH operation
Expand Down
37 changes: 0 additions & 37 deletions src/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,20 @@ use zeroize::Zeroize;
mod dhkem;
pub use dhkem::*;

#[cfg(feature = "serde_impls")]
use serde::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};

/// Represents authenticated encryption functionality
pub trait Kem: Sized {
/// The key exchange's public key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(feature = "serde_impls")]
type PublicKey: Clone
+ Debug
+ PartialEq
+ Eq
+ Serializable
+ Deserializable
+ SerdeSerialize
+ for<'a> SerdeDeserialize<'a>;
/// The key exchange's public key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(not(feature = "serde_impls"))]
type PublicKey: Clone + Debug + PartialEq + Eq + Serializable + Deserializable;

/// The key exchange's private key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(feature = "serde_impls")]
type PrivateKey: Clone
+ PartialEq
+ Eq
+ Serializable
+ Deserializable
+ SerdeSerialize
+ for<'a> SerdeDeserialize<'a>;

/// The key exchange's private key type. If you want to generate a keypair, see
/// `Kem::gen_keypair` or `Kem::derive_keypair`
#[cfg(not(feature = "serde_impls"))]
type PrivateKey: Clone + PartialEq + Eq + Serializable + Deserializable;

/// Computes the public key of a given private key
fn sk_to_pk(sk: &Self::PrivateKey) -> Self::PublicKey;

/// The encapsulated key for this KEM. This is used by the recipient to derive the shared
/// secret.
#[cfg(feature = "serde_impls")]
type EncappedKey: Clone
+ Serializable
+ Deserializable
+ SerdeSerialize
+ for<'a> SerdeDeserialize<'a>;
/// The encapsulated key for this KEM. This is used by the recipient to derive the shared
/// secret.
#[cfg(not(feature = "serde_impls"))]
type EncappedKey: Clone + Serializable + Deserializable;

/// The size of a shared secret in this KEM
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ mod op_mode;
mod setup;
mod single_shot;

#[cfg(feature = "serde_impls")]
mod serde_impls;

#[doc(inline)]
pub use kem::Kem;
#[doc(inline)]
Expand Down
175 changes: 0 additions & 175 deletions src/serde_impls.rs

This file was deleted.

0 comments on commit 362d7bc

Please sign in to comment.