line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# string::hash Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::String::Hash; |
7
|
1
|
|
|
1
|
|
806
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
618
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable sha sha1 sha256 sha512 md5 md5sum sum) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
sha1 => [ qw(data) ], |
20
|
|
|
|
|
|
|
sha256 => [ qw(data) ], |
21
|
|
|
|
|
|
|
sha512 => [ qw(data) ], |
22
|
|
|
|
|
|
|
md5 => [ qw(data) ], |
23
|
|
|
|
|
|
|
mmh3 => [ qw(data signed|OPTIONAL) ], |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
require_modules => { |
26
|
|
|
|
|
|
|
'Crypt::Digest' => [ ], |
27
|
|
|
|
|
|
|
'Digest::MurmurHash3' => [ qw(murmur32) ], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _hash { |
33
|
0
|
|
|
0
|
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
my ($function, $data) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg($function, $data) or return; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
eval("use Crypt::Digest qw(digest_data_hex);"); |
39
|
0
|
0
|
|
|
|
|
if ($@) { |
40
|
0
|
|
|
|
|
|
chomp($@); |
41
|
0
|
|
|
|
|
|
return $self->log->error("$function: unable to load function: $@"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $hash; |
45
|
0
|
|
|
|
|
|
eval { |
46
|
0
|
|
|
|
|
|
$hash = Crypt::Digest::digest_data_hex(uc($function), $data); |
47
|
|
|
|
|
|
|
}; |
48
|
0
|
0
|
|
|
|
|
if ($@) { |
49
|
0
|
|
|
|
|
|
chomp($@); |
50
|
0
|
|
|
|
|
|
return $self->log->error("$function: unable to compute hash: $@"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return $hash; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub sha1 { |
57
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
58
|
0
|
|
|
|
|
|
my ($data) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $self->_hash('sha1', $data); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub sha256 { |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
my ($data) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self->_hash('sha256', $data); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub sha512 { |
71
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my ($data) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $self->_hash('sha512', $data); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub md5 { |
78
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
my ($data) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return $self->_hash('md5', $data); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub mmh3 { |
85
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
86
|
0
|
|
|
|
|
|
my ($data, $signed) = @_; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
0
|
|
|
|
$signed ||= 0; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $hash; |
91
|
0
|
|
|
|
|
|
eval { |
92
|
0
|
|
|
|
|
|
$hash = Digest::MurmurHash3::murmur32($data, 0, $signed); |
93
|
|
|
|
|
|
|
}; |
94
|
0
|
0
|
|
|
|
|
if ($@) { |
95
|
0
|
|
|
|
|
|
chomp($@); |
96
|
0
|
|
|
|
|
|
return $self->log->error("mmh3: unable to compute hash: $@"); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $hash; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |