Filename | /usr/lib/perl5/5.14/Digest/base.pm |
Statements | Executed 6 statements in 715µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 218µs | 223µs | BEGIN@3 | Digest::base::
1 | 1 | 1 | 14µs | 49µs | BEGIN@4 | Digest::base::
0 | 0 | 0 | 0s | 0s | add_bits | Digest::base::
0 | 0 | 0 | 0s | 0s | addfile | Digest::base::
0 | 0 | 0 | 0s | 0s | b64digest | Digest::base::
0 | 0 | 0 | 0s | 0s | hexdigest | Digest::base::
0 | 0 | 0 | 0s | 0s | reset | Digest::base::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Digest::base; | ||||
2 | |||||
3 | 2 | 61µs | 2 | 228µs | # spent 223µs (218+5) within Digest::base::BEGIN@3 which was called:
# once (218µs+5µs) by installer::windows::file::BEGIN@30 at line 3 # spent 223µs making 1 call to Digest::base::BEGIN@3
# spent 5µs making 1 call to strict::import |
4 | 2 | 644µs | 2 | 85µs | # spent 49µs (14+36) within Digest::base::BEGIN@4 which was called:
# once (14µs+36µs) by installer::windows::file::BEGIN@30 at line 4 # spent 49µs making 1 call to Digest::base::BEGIN@4
# spent 36µs making 1 call to vars::import |
5 | 1 | 1µs | $VERSION = "1.16"; | ||
6 | |||||
7 | # subclass is supposed to implement at least these | ||||
8 | sub new; | ||||
9 | sub clone; | ||||
10 | sub add; | ||||
11 | sub digest; | ||||
12 | |||||
13 | sub reset { | ||||
14 | my $self = shift; | ||||
15 | $self->new(@_); # ugly | ||||
16 | } | ||||
17 | |||||
18 | sub addfile { | ||||
19 | my ($self, $handle) = @_; | ||||
20 | |||||
21 | my $n; | ||||
22 | my $buf = ""; | ||||
23 | |||||
24 | while (($n = read($handle, $buf, 4*1024))) { | ||||
25 | $self->add($buf); | ||||
26 | } | ||||
27 | unless (defined $n) { | ||||
28 | require Carp; | ||||
29 | Carp::croak("Read failed: $!"); | ||||
30 | } | ||||
31 | |||||
32 | $self; | ||||
33 | } | ||||
34 | |||||
35 | sub add_bits { | ||||
36 | my $self = shift; | ||||
37 | my $bits; | ||||
38 | my $nbits; | ||||
39 | if (@_ == 1) { | ||||
40 | my $arg = shift; | ||||
41 | $bits = pack("B*", $arg); | ||||
42 | $nbits = length($arg); | ||||
43 | } | ||||
44 | else { | ||||
45 | ($bits, $nbits) = @_; | ||||
46 | } | ||||
47 | if (($nbits % 8) != 0) { | ||||
48 | require Carp; | ||||
49 | Carp::croak("Number of bits must be multiple of 8 for this algorithm"); | ||||
50 | } | ||||
51 | return $self->add(substr($bits, 0, $nbits/8)); | ||||
52 | } | ||||
53 | |||||
54 | sub hexdigest { | ||||
55 | my $self = shift; | ||||
56 | return unpack("H*", $self->digest(@_)); | ||||
57 | } | ||||
58 | |||||
59 | sub b64digest { | ||||
60 | my $self = shift; | ||||
61 | require MIME::Base64; | ||||
62 | my $b64 = MIME::Base64::encode($self->digest(@_), ""); | ||||
63 | $b64 =~ s/=+$//; | ||||
64 | return $b64; | ||||
65 | } | ||||
66 | |||||
67 | 1 | 9µs | 1; | ||
68 | |||||
69 | __END__ |