Skip to content

Commit 504f0a6

Browse files
authored
belt-ctr: use type alias to define BeltCtr (#112)
Unfortunately, type defaults used previously are not handled well in the current Rust. For example, it could be seen in the readme example where we can not use `let mut cipher = BeltCtr::new_from_slices(key, iv)?;` and instead have to use either `let mut cipher: BeltCtr = BeltCtr::new_from_slices(key, iv)?;` or `<BeltCtr>::new_from_slices`.
1 parent 0ff441c commit 504f0a6

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

belt-ctr/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,19 @@ 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.0 (UNRELEASED)
9+
## Added
10+
- `GenericBeltCtr` and `GenericBeltCtrCore` types ([#112])
11+
12+
## Changed
13+
- Bump `cipher` from `0.4` to `0.5` ([#56])
14+
- Edition changed to 2024 and MSRV bumped to 1.85 ([#76])
15+
- Relax MSRV policy and allow MSRV bumps in patch releases
16+
- Use type aliases instead of type defaults to define default `belt-block` implementation ([#112])
17+
18+
[#56]: https://github.com/RustCrypto/block-modes/pull/56
19+
[#76]: https://github.com/RustCrypto/block-modes/pull/76
20+
[#112]: https://github.com/RustCrypto/block-modes/pull/112
21+
822
## 0.1.0 (2023-04-02)
923
- Initial release

belt-ctr/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let ciphertext: &[u8; 34] = &hex!(
3232
"7D1B"
3333
);
3434

35-
let mut cipher: BeltCtr = BeltCtr::new_from_slices(key, iv).unwrap();
35+
let mut cipher = BeltCtr::new_from_slices(key, iv).unwrap();
3636

3737
// encrypt in-place
3838
let mut buf = plaintext.clone();

belt-ctr/src/lib.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ use core::fmt;
2121
use cipher::zeroize::{Zeroize, ZeroizeOnDrop};
2222

2323
/// Byte-level BelT CTR
24-
pub type BeltCtr<C = BeltBlock> = StreamCipherCoreWrapper<BeltCtrCore<C>>;
25-
24+
pub type BeltCtr = GenericBeltCtr<BeltBlock>;
2625
/// Block-level BelT CTR
27-
pub struct BeltCtrCore<C = BeltBlock>
26+
pub type BeltCtrCore = GenericBeltCtrCore<BeltBlock>;
27+
/// Byte-level BelT CTR generic over block cipher implementation
28+
pub type GenericBeltCtr<C> = StreamCipherCoreWrapper<GenericBeltCtrCore<C>>;
29+
30+
/// Block-level BelT CTR generic over block cipher implementation
31+
pub struct GenericBeltCtrCore<C>
2832
where
2933
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
3034
{
@@ -33,7 +37,7 @@ where
3337
s_init: u128,
3438
}
3539

36-
impl<C> StreamCipherCore for BeltCtrCore<C>
40+
impl<C> StreamCipherCore for GenericBeltCtrCore<C>
3741
where
3842
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
3943
{
@@ -65,7 +69,7 @@ where
6569
}
6670
}
6771

68-
impl<C> StreamCipherSeekCore for BeltCtrCore<C>
72+
impl<C> StreamCipherSeekCore for GenericBeltCtrCore<C>
6973
where
7074
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
7175
{
@@ -80,28 +84,28 @@ where
8084
}
8185
}
8286

83-
impl<C> BlockSizeUser for BeltCtrCore<C>
87+
impl<C> BlockSizeUser for GenericBeltCtrCore<C>
8488
where
8589
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
8690
{
8791
type BlockSize = C::BlockSize;
8892
}
8993

90-
impl<C> IvSizeUser for BeltCtrCore<C>
94+
impl<C> IvSizeUser for GenericBeltCtrCore<C>
9195
where
9296
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
9397
{
9498
type IvSize = C::BlockSize;
9599
}
96100

97-
impl<C> InnerUser for BeltCtrCore<C>
101+
impl<C> InnerUser for GenericBeltCtrCore<C>
98102
where
99103
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
100104
{
101105
type Inner = C;
102106
}
103107

104-
impl<C> InnerIvInit for BeltCtrCore<C>
108+
impl<C> InnerIvInit for GenericBeltCtrCore<C>
105109
where
106110
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
107111
{
@@ -118,7 +122,7 @@ where
118122
}
119123
}
120124

121-
impl<C> IvState for BeltCtrCore<C>
125+
impl<C> IvState for GenericBeltCtrCore<C>
122126
where
123127
C: BlockCipherEncrypt + BlockCipherDecrypt + BlockSizeUser<BlockSize = U16>,
124128
{
@@ -129,7 +133,7 @@ where
129133
}
130134
}
131135

132-
impl<C> AlgorithmName for BeltCtrCore<C>
136+
impl<C> AlgorithmName for GenericBeltCtrCore<C>
133137
where
134138
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16> + AlgorithmName,
135139
{
@@ -140,7 +144,7 @@ where
140144
}
141145
}
142146

143-
impl<C> fmt::Debug for BeltCtrCore<C>
147+
impl<C> fmt::Debug for GenericBeltCtrCore<C>
144148
where
145149
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16> + AlgorithmName,
146150
{
@@ -152,7 +156,7 @@ where
152156
}
153157
}
154158

155-
impl<C: BlockCipherEncrypt> Drop for BeltCtrCore<C>
159+
impl<C: BlockCipherEncrypt> Drop for GenericBeltCtrCore<C>
156160
where
157161
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
158162
{
@@ -166,7 +170,7 @@ where
166170
}
167171

168172
#[cfg(feature = "zeroize")]
169-
impl<C> ZeroizeOnDrop for BeltCtrCore<C> where
173+
impl<C> ZeroizeOnDrop for GenericBeltCtrCore<C> where
170174
C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16> + ZeroizeOnDrop
171175
{
172176
}

0 commit comments

Comments
 (0)