1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
extern crate crypto;
use crypto::digest::Digest;
pub struct Checksum {
name: String,
algo: Box<Digest>
}
impl Checksum {
pub fn new<T: 'static + Digest>(algo_name: String, algorithm: T) -> Checksum {
Checksum {
name: algo_name,
algo: Box::new(algorithm)
}
}
#[inline]
pub fn input(&mut self, slice_content: &[u8]) {
self.algo.input(slice_content);
}
#[inline]
pub fn result(&mut self) -> String {
format!("{:8} - {}", self.name, self.algo.result_str())
}
#[inline(always)]
pub fn checksum(&mut self) -> String {
self.algo.result_str()
}
#[inline(always)]
pub fn reset(&mut self) {
self.algo.reset();
}
#[inline]
pub fn get_file_ext(&self) -> String {
self.name[0..self.name.len()-1].chars()
.map(|elem| elem.to_lowercase().next().unwrap())
.collect()
}
#[inline(always)]
pub fn get_type_string(&self) -> String {
format!("{:8} - ", self.name)
}
}
impl PartialEq for Checksum {
fn eq(&self, right: &Checksum) -> bool {
self.name == right.name
}
fn ne(&self, right: &Checksum) -> bool {
self.name != right.name
}
}