[qmc2/rc4] refactor: create box of slice instead of convert later
This commit is contained in:
parent
6791dec745
commit
f75a3ccb34
@ -17,13 +17,13 @@ pub struct QMC2RC4 {
|
||||
impl QMC2RC4 {
|
||||
pub fn new(key: &[u8]) -> Self {
|
||||
let mut rc4 = RC4::new(key);
|
||||
let mut key_stream = [0u8; RC4_STREAM_CACHE_SIZE];
|
||||
rc4.derive(&mut key_stream);
|
||||
let mut key_stream = Box::new([0u8; RC4_STREAM_CACHE_SIZE]);
|
||||
rc4.derive(&mut key_stream[..]);
|
||||
|
||||
Self {
|
||||
hash: hash(key),
|
||||
key: key.into(),
|
||||
key_stream: key_stream.into(),
|
||||
key_stream,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,11 @@ impl RC4 {
|
||||
self.state[index]
|
||||
}
|
||||
|
||||
pub fn derive(&mut self, buffer: &mut [u8]) {
|
||||
for item in buffer.iter_mut() {
|
||||
pub fn derive<T>(&mut self, buffer: &mut T)
|
||||
where
|
||||
T: AsMut<[u8]> + ?Sized,
|
||||
{
|
||||
for item in buffer.as_mut().iter_mut() {
|
||||
*item ^= self.generate();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user