Skip to content

Commit f73c4bc

Browse files
authored
crypto-common: add SetIvState trait (#2420)
1 parent 94f108f commit f73c4bc

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

crypto-common/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.2.2 (UNRELEASED)
9+
### Added
10+
- `SetIvState` trait ([#2420])
11+
12+
[#2420]: https://github.com/RustCrypto/traits/pull/2420
13+
814
## 0.2.1 (2026-02-25)
915
### Changed
1016
- `BlockSizeUser::BlockSize` is no longer bounded by `BlockSizes` ([#2309])

crypto-common/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,22 @@ pub trait IvState: IvSizeUser {
310310
fn iv_state(&self) -> Iv<Self>;
311311
}
312312

313+
/// Trait for setting current IV state.
314+
// TODO: merge with `IvState` in the next breaking release
315+
pub trait SetIvState: IvState {
316+
/// Set IV.
317+
fn set_iv(&mut self, iv: &Iv<Self>);
318+
319+
/// Execute the `f` closure with the current state and reset it back
320+
/// to the original state before the method returns.
321+
fn peek<T>(&mut self, f: impl FnOnce(&mut Self) -> T) -> T {
322+
let iv = self.iv_state();
323+
let res = f(self);
324+
self.set_iv(&iv);
325+
res
326+
}
327+
}
328+
313329
impl<T> KeySizeUser for T
314330
where
315331
T: InnerUser,

0 commit comments

Comments
 (0)