From 7e8218e9f40024412b7d813bf5052ed83036e3f3 Mon Sep 17 00:00:00 2001 From: Sachymetsu Date: Thu, 2 Apr 2026 07:43:08 +0200 Subject: [PATCH] BufferSlice reset method --- sachy-crypto/Cargo.toml | 8 +++++++- sachy-crypto/src/lib.rs | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sachy-crypto/Cargo.toml b/sachy-crypto/Cargo.toml index c0ff474..dab2dc9 100644 --- a/sachy-crypto/Cargo.toml +++ b/sachy-crypto/Cargo.toml @@ -7,9 +7,15 @@ license.workspace = true version.workspace = true rust-version.workspace = true +[features] +alloc = ["chacha20poly1305/alloc"] + [dependencies] -chacha20poly1305 = { version = "=0.11.0-rc.3", default-features = false, features = ["getrandom", "alloc"] } +chacha20poly1305 = { version = "=0.11.0-rc.3", default-features = false, features = ["getrandom"] } k256 = { version = "=0.14.0-rc.8", default-features = false, features = ["ecdh", "getrandom"] } sha2 = { version = "=0.11.0-rc.5", default-features = false, features = [] } dhkem = { version = "0.1.0-rc.0", features = ["getrandom", "k256"] } elliptic-curve = { version = "0.14.0-rc.28", default-features = false, features = ["ecdh"] } + +[dev-dependencies] +chacha20poly1305 = { version = "=0.11.0-rc.3", default-features = false, features = ["getrandom", "alloc"] } diff --git a/sachy-crypto/src/lib.rs b/sachy-crypto/src/lib.rs index 4b7d837..48e4bdc 100644 --- a/sachy-crypto/src/lib.rs +++ b/sachy-crypto/src/lib.rs @@ -300,6 +300,10 @@ impl<'a> BufferSlice<'a> { slice, } } + + pub fn reset(&mut self) { + self.end = self.slice.len(); + } } impl AsRef<[u8]> for BufferSlice<'_> { @@ -356,6 +360,10 @@ mod tests { assert_eq!(buf_slice.extend_from_slice(&[0,0,0,0,0,0]), Ok(())); assert_eq!(buf_slice.len(), 70); + + buf_slice.reset(); + + assert_eq!(buf_slice.len(), 128); } #[test] -- 2.51.2