Skip to content

Commit e7a7e3b

Browse files
committed
fix imports, add dummy_stream_cipher_core test
1 parent 7cea702 commit e7a7e3b

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cipher/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ blobby = { version = "0.4.0-pre.1", optional = true }
2121
block-buffer = { version = "0.11.0-rc.5", optional = true }
2222
zeroize = { version = "1.8", optional = true, default-features = false }
2323

24+
[dev-dependencies]
25+
hex-literal = "1"
26+
2427
[features]
2528
alloc = []
2629
block-padding = ["inout/block-padding"]

cipher/tests/stream.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use cipher::{
2-
BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, ParBlocksSizeUser, StreamCipher,
3-
StreamCipherBackend, StreamCipherClosure, StreamCipherCore, StreamCipherCoreWrapper,
4-
StreamCipherSeek, StreamCipherSeekCore,
2+
BlockSizeUser, IvSizeUser, KeyIvInit, KeySizeUser, ParBlocksSizeUser, StreamCipherBackend,
3+
StreamCipherClosure, StreamCipherCore, StreamCipherSeekCore,
54
consts::{U1, U4, U16},
65
};
6+
#[cfg(feature = "stream-wrapper")]
7+
use cipher::{StreamCipher, StreamCipherCoreWrapper, StreamCipherSeek};
8+
use hex_literal::hex;
79

810
const KEY: [u8; 4] = [0, 1, 2, 3];
911
const IV: [u8; 4] = [4, 5, 6, 7];
@@ -85,33 +87,40 @@ impl StreamCipherSeekCore for DummyStreamCipherCore {
8587
#[cfg(feature = "stream-wrapper")]
8688
pub type DummyStreamCipher = StreamCipherCoreWrapper<DummyStreamCipherCore>;
8789

90+
#[test]
91+
fn dummy_stream_cipher_core() {
92+
let mut cipher = DummyStreamCipherCore::new(&KEY.into(), &IV.into());
93+
assert_eq!(cipher.get_block_pos(), 0);
94+
95+
let mut block = [0u8; 16].into();
96+
cipher.write_keystream_block(&mut block);
97+
assert_eq!(block, hex!("e82393543cc96089305116003a417acc"));
98+
assert_eq!(cipher.get_block_pos(), 1);
99+
100+
cipher.set_block_pos(200);
101+
assert_eq!(cipher.get_block_pos(), 200);
102+
103+
cipher.write_keystream_block(&mut block);
104+
assert_eq!(block, hex!("28a96998fe4874ffb0ce9b046c6a9ddb"));
105+
assert_eq!(cipher.get_block_pos(), 201);
106+
}
107+
88108
#[test]
89109
#[cfg(feature = "stream-wrapper")]
90110
fn dummy_stream_cipher() {
91111
let mut cipher = DummyStreamCipher::new(&KEY.into(), &IV.into());
92-
93112
assert_eq!(cipher.current_pos::<u64>(), 0);
94113

95114
let mut buf = [0u8; 20];
96-
97115
cipher.apply_keystream(&mut buf);
116+
assert_eq!(buf, hex!("e82393543cc96089305116003a417accd073384a"));
98117
assert_eq!(cipher.current_pos::<usize>(), buf.len());
99118

100-
let expected = [
101-
232, 35, 147, 84, 60, 201, 96, 137, 48, 81, 22, 0, 58, 65, 122, 204, 208, 115, 56, 74,
102-
];
103-
assert_eq!(buf, expected);
104-
105119
const SEEK_POS: usize = 500;
106-
107120
cipher.seek(SEEK_POS);
108121
cipher.apply_keystream(&mut buf);
122+
assert_eq!(buf, hex!("6b014c6a3c376b13c4720590d26147c5ebf334c5"));
109123
assert_eq!(cipher.current_pos::<usize>(), SEEK_POS + buf.len());
110-
111-
let expected = [
112-
107, 1, 76, 106, 60, 55, 107, 19, 196, 114, 5, 144, 210, 97, 71, 197, 235, 243, 52, 197,
113-
];
114-
assert_eq!(buf, expected);
115124
}
116125

117126
#[test]

0 commit comments

Comments
 (0)