From add6b76bb7e5bfe767aa5011941c6638fb4fec72 Mon Sep 17 00:00:00 2001 From: David Pollack Date: Fri, 27 Sep 2024 23:33:07 +1000 Subject: [PATCH] Add `bytes` feature passthrough (#631) This allows you to use a `BytesMut` as a `Buffer` with `chacha20poly1305` (or other AEADs) by only including `chacha20poly1305` in your Cargo.toml and not also having to include `aead` in your Cargo.toml. This is similar to how `heapless` and `arrayvec` currently have feature passthroughs. Fixes #600 --- Cargo.lock | 7 +++++++ aes-gcm-siv/Cargo.toml | 1 + aes-gcm-siv/src/lib.rs | 4 +++- aes-gcm/Cargo.toml | 1 + aes-gcm/src/lib.rs | 4 +++- aes-siv/Cargo.toml | 1 + aes-siv/src/lib.rs | 4 +++- ascon-aead/Cargo.toml | 1 + ascon-aead/src/lib.rs | 5 ++++- ccm/Cargo.toml | 1 + chacha20poly1305/Cargo.toml | 1 + chacha20poly1305/src/lib.rs | 4 +++- deoxys/Cargo.toml | 1 + deoxys/src/lib.rs | 4 +++- eax/Cargo.toml | 1 + eax/src/lib.rs | 4 +++- mgm/Cargo.lock | 7 +++++++ mgm/Cargo.toml | 1 + ocb3/Cargo.toml | 1 + 19 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af9862e6..eb9addf8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,7 @@ checksum = "b5f451b77e2f92932dc411da6ef9f3d33efad68a6f14a7a83e559453458e85ac" dependencies = [ "arrayvec", "blobby", + "bytes", "crypto-common", "heapless", ] @@ -133,6 +134,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "ccm" version = "0.5.0" diff --git a/aes-gcm-siv/Cargo.toml b/aes-gcm-siv/Cargo.toml index 86d14301..f3c4c6b7 100644 --- a/aes-gcm-siv/Cargo.toml +++ b/aes-gcm-siv/Cargo.toml @@ -33,6 +33,7 @@ default = ["aes", "alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/aes-gcm-siv/src/lib.rs b/aes-gcm-siv/src/lib.rs index c1e2f9e5..29ee1d71 100644 --- a/aes-gcm-siv/src/lib.rs +++ b/aes-gcm-siv/src/lib.rs @@ -80,7 +80,9 @@ //! //! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of //! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as -//! [`aead::arrayvec::ArrayVec`]). +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the +//! [`aead`] crate as [`aead::bytes::BytesMut`]). pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; diff --git a/aes-gcm/Cargo.toml b/aes-gcm/Cargo.toml index d21453fd..f9bedcd5 100644 --- a/aes-gcm/Cargo.toml +++ b/aes-gcm/Cargo.toml @@ -34,6 +34,7 @@ default = ["aes", "alloc", "getrandom"] std = ["aead/std", "cipher/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/aes-gcm/src/lib.rs b/aes-gcm/src/lib.rs index b7cb8b5e..feb8902a 100644 --- a/aes-gcm/src/lib.rs +++ b/aes-gcm/src/lib.rs @@ -106,7 +106,9 @@ //! //! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of //! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as -//! [`aead::arrayvec::ArrayVec`]). +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the +//! [`aead`] crate as [`aead::bytes::BytesMut`]). pub use aead::{self, AeadCore, AeadInPlace, Error, Key, KeyInit, KeySizeUser}; diff --git a/aes-siv/Cargo.toml b/aes-siv/Cargo.toml index 4a23eabf..23d24258 100644 --- a/aes-siv/Cargo.toml +++ b/aes-siv/Cargo.toml @@ -38,6 +38,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/aes-siv/src/lib.rs b/aes-siv/src/lib.rs index 40752006..74cfe44a 100644 --- a/aes-siv/src/lib.rs +++ b/aes-siv/src/lib.rs @@ -80,7 +80,9 @@ //! //! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of //! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as -//! [`aead::arrayvec::ArrayVec`]). +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the +//! [`aead`] crate as [`aead::bytes::BytesMut`]). #[cfg(feature = "alloc")] extern crate alloc; diff --git a/ascon-aead/Cargo.toml b/ascon-aead/Cargo.toml index 59100a54..48907aaa 100644 --- a/ascon-aead/Cargo.toml +++ b/ascon-aead/Cargo.toml @@ -29,6 +29,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/ascon-aead/src/lib.rs b/ascon-aead/src/lib.rs index f28b9f32..2f0251d4 100644 --- a/ascon-aead/src/lib.rs +++ b/ascon-aead/src/lib.rs @@ -96,7 +96,10 @@ //! ``` //! //! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of -//! [`aead::Buffer`] for `arrayvec::ArrayVec`. +//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the +//! [`aead`] crate as [`aead::bytes::BytesMut`]). #[cfg(feature = "zeroize")] pub use zeroize; diff --git a/ccm/Cargo.toml b/ccm/Cargo.toml index 187e2f1a..0ebf7311 100644 --- a/ccm/Cargo.toml +++ b/ccm/Cargo.toml @@ -29,6 +29,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/chacha20poly1305/Cargo.toml b/chacha20poly1305/Cargo.toml index 63b60e9f..24ad4c59 100644 --- a/chacha20poly1305/Cargo.toml +++ b/chacha20poly1305/Cargo.toml @@ -34,6 +34,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/chacha20poly1305/src/lib.rs b/chacha20poly1305/src/lib.rs index 55999fc9..60607f6b 100644 --- a/chacha20poly1305/src/lib.rs +++ b/chacha20poly1305/src/lib.rs @@ -92,7 +92,9 @@ //! //! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of //! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as -//! [`aead::arrayvec::ArrayVec`]). +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the +//! [`aead`] crate as [`aead::bytes::BytesMut`]). //! //! ## [`XChaCha20Poly1305`] //! diff --git a/deoxys/Cargo.toml b/deoxys/Cargo.toml index 56a4c387..1aedef4d 100644 --- a/deoxys/Cargo.toml +++ b/deoxys/Cargo.toml @@ -32,6 +32,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/deoxys/src/lib.rs b/deoxys/src/lib.rs index ab053fc5..0dbcd2af 100644 --- a/deoxys/src/lib.rs +++ b/deoxys/src/lib.rs @@ -100,7 +100,9 @@ //! //! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of //! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as -//! [`aead::arrayvec::ArrayVec`]). +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the +//! [`aead`] crate as [`aead::bytes::BytesMut`]). /// Deoxys-BC implementations. mod deoxys_bc; diff --git a/eax/Cargo.toml b/eax/Cargo.toml index b7eef49e..04996764 100644 --- a/eax/Cargo.toml +++ b/eax/Cargo.toml @@ -35,6 +35,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/eax/src/lib.rs b/eax/src/lib.rs index 75277322..67a3655f 100644 --- a/eax/src/lib.rs +++ b/eax/src/lib.rs @@ -83,7 +83,9 @@ //! //! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of //! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as -//! [`aead::arrayvec::ArrayVec`]). +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the +//! [`aead`] crate as [`aead::bytes::BytesMut`]). //! //! ## Custom Tag Length //! diff --git a/mgm/Cargo.lock b/mgm/Cargo.lock index eee0085d..20a5b864 100644 --- a/mgm/Cargo.lock +++ b/mgm/Cargo.lock @@ -10,6 +10,7 @@ checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ "arrayvec", "blobby", + "bytes", "crypto-common", "generic-array", "heapless", @@ -48,6 +49,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + [[package]] name = "cfg-if" version = "1.0.0" diff --git a/mgm/Cargo.toml b/mgm/Cargo.toml index c37ed082..655f20bb 100644 --- a/mgm/Cargo.toml +++ b/mgm/Cargo.toml @@ -35,6 +35,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"] diff --git a/ocb3/Cargo.toml b/ocb3/Cargo.toml index 941779a1..e4b221b2 100644 --- a/ocb3/Cargo.toml +++ b/ocb3/Cargo.toml @@ -33,6 +33,7 @@ default = ["alloc", "getrandom"] std = ["aead/std", "alloc"] alloc = ["aead/alloc"] arrayvec = ["aead/arrayvec"] +bytes = ["aead/bytes"] getrandom = ["aead/getrandom", "rand_core"] heapless = ["aead/heapless"] rand_core = ["aead/rand_core"]