| 1 | package Digest::base; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 6 | our $VERSION = "1.20"; | |||||||||
| 7 | |||||||||||
| 8 | # subclass is supposed to implement at least these | ||||||||||
| 9 | sub new; | ||||||||||
| 10 | sub clone; | ||||||||||
| 11 | sub add; | ||||||||||
| 12 | sub digest; | ||||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | sub reset { | ||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 15 | 0 | my $self = shift; | |||||||||
| 16 | 0 | $self->new(@_); # ugly | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 4 | ▶ | sub addfile { | ||||||||
|
Subroutine
addfile: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||
| 20 | 4 | my ( $self, $handle ) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 4 | my $n; | |||||||||
| 23 | 4 | my $buf = ""; | |||||||||
| 24 | |||||||||||
| 25 | 4 | ▶ | while ( ( $n = read( $handle, $buf, 4 * 1024 ) ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 4 | $self->add($buf); | |||||||||
| 27 | } | ||||||||||
| 28 | 4 | ▶ | unless ( defined $n ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | require Carp; | |||||||||
| 30 | 0 | Carp::croak("Read failed: $!"); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 4 | $self; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 5 | ▶ | sub add_bits { | ||||||||
|
Subroutine
add_bits: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 37 | 5 | my $self = shift; | |||||||||
| 38 | 5 | my $bits; | |||||||||
| 39 | my $nbits; | ||||||||||
| 40 | 5 | ▶ | if ( @_ == 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 2 | my $arg = shift; | |||||||||
| 42 | 2 | $bits = pack( "B*", $arg ); | |||||||||
| 43 | 2 | $nbits = length($arg); | |||||||||
| 44 | } | ||||||||||
| 45 | else { | ||||||||||
| 46 | 3 | ( $bits, $nbits ) = @_; | |||||||||
| 47 | } | ||||||||||
| 48 | 5 | ▶ | if ( ( $nbits % 8 ) != 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 2 | require Carp; | |||||||||
| 50 | 2 | Carp::croak("Number of bits must be multiple of 8 for this algorithm"); | |||||||||
| 51 | } | ||||||||||
| 52 | 3 | return $self->add( substr( $bits, 0, $nbits / 8 ) ); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 3 | ▶ | sub hexdigest { | ||||||||
|
Subroutine
hexdigest: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 56 | 3 | my $self = shift; | |||||||||
| 57 | 3 | return unpack( "H*", $self->digest(@_) ); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 3 | ▶ | sub b64digest { | ||||||||
|
Subroutine
b64digest: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 61 | 3 | my $self = shift; | |||||||||
| 62 | 3 | my $b64 = $self->base64_padded_digest; | |||||||||
| 63 | 3 | $b64 =~ s/=+$//; | |||||||||
| 64 | 3 | return $b64; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 4 | ▶ | sub base64_padded_digest { | ||||||||
|
Subroutine
base64_padded_digest: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 68 | 4 | my $self = shift; | |||||||||
| 69 | 4 | require MIME::Base64; | |||||||||
| 70 | 4 | return MIME::Base64::encode( $self->digest(@_), "" ); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 6 | 1; | |||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||