1use md5::compute;
2use std::io;
3
4static MD5_LENGTH: u32 = 16;
5
6pub fn other(desc: &str) -> io::Error {
7 io::Error::new(io::ErrorKind::Other, desc)
8}
9
10pub fn eof() -> io::Error {
11 io::Error::new(io::ErrorKind::UnexpectedEof, "early eof")
12}
13
14pub fn generate_key(data: &[u8], key_len: usize) -> Vec<u8> {
15 let count = (key_len as f32 / MD5_LENGTH as f32).ceil() as u32;
16 let mut key = Vec::from(&compute(data)[..]);
17 let mut start = 0;
18 for _ in 1..count {
19 start += MD5_LENGTH;
20 let mut d = Vec::from(&key[(start - MD5_LENGTH) as usize..start as usize]);
21 d.extend_from_slice(data);
22 let d = compute(d);
23 key.extend_from_slice(&*d);
24 }
25 key
26}