| 1 | package Crypt::OpenPGP::Digest; | ||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 11 | our $VERSION = '1.21'; # VERSION | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 11 | ▶ | use parent qw( Crypt::OpenPGP::ErrorHandler ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 11 | our %ALG = ( | |||||||||||||||||||
| 10 | 1 => 'MD5', | ||||||||||||||||||||
| 11 | 2 => 'SHA1', | ||||||||||||||||||||
| 12 | 3 => 'RIPEMD160', | ||||||||||||||||||||
| 13 | 8 => 'SHA256', | ||||||||||||||||||||
| 14 | 9 => 'SHA384', | ||||||||||||||||||||
| 15 | 10 => 'SHA512', | ||||||||||||||||||||
| 16 | 11 => 'SHA224', | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | 11 | our %ALG_BY_NAME = map { $ALG{$_} => $_ } keys %ALG; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 30 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 21 | 30 | my $class = shift; | |||||||||||||||||||
| 22 | 30 | my $alg = shift; | |||||||||||||||||||
| 23 | 30 | ▶ | $alg = $ALG{$alg} || $alg; | ||||||||||||||||||
|
Condition66%2/3
$Crypt::OpenPGP::Digest::ALG{$alg} || $alg
MC/DC0%0/2
$Crypt::OpenPGP::Digest::ALG{$alg} || $alg
$Crypt::OpenPGP::Digest::ALG{$alg}
$alg
Truth table66%2/3
A || B
A= $Crypt::OpenPGP::Digest::ALG{$alg}B= $alg
| |||||||||||||||||||||
| 24 | 30 | ▶ | return $class->error("Unsupported digest algorithm '$alg'") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | unless $alg =~ /^\D/; | ||||||||||||||||||||
| 26 | 30 | my $pkg = join '::', $class, $alg; | |||||||||||||||||||
| 27 | my $dig = bless { __alg => $alg, | ||||||||||||||||||||
| 28 | 30 | __alg_id => $ALG_BY_NAME{$alg} }, $pkg; | |||||||||||||||||||
| 29 | 30 | $dig->init(@_); | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | ▶ | sub init { $_[0] } | ||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 33 | 28 | ▶ | sub hash { $_[0]->{md}->($_[1]) } | ||||||||||||||||||
|
Subroutine
hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 10 | ▶ | sub alg { | ||||||||||||||||||
|
Subroutine
alg: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 36 | 10 | ▶ | return $_[0]->{__alg} if ref($_[0]); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 3 | ▶ | $ALG{$_[1]} || $_[1]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 7 | ▶ | sub alg_id { | ||||||||||||||||||
|
Subroutine
alg_id: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||
| 41 | 7 | ▶ | return $_[0]->{__alg_id} if ref($_[0]); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | ▶ | $ALG_BY_NAME{$_[1]} || $_[1]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | ▶ | sub supported { | ||||||||||||||||||
|
Subroutine
supported: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 46 | 0 | my $class = shift; | |||||||||||||||||||
| 47 | 0 | my %s; | |||||||||||||||||||
| 48 | 0 | for my $did (keys %ALG) { | |||||||||||||||||||
| 49 | 0 | my $digest = $class->new($did); | |||||||||||||||||||
| 50 | 0 | ▶ | $s{$did} = $digest->alg if $digest; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | 0 | \%s; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | package Crypt::OpenPGP::Digest::MD5; | ||||||||||||||||||||
| 56 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 11 | ▶ | use parent qw( Crypt::OpenPGP::Digest ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 4 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 62 | 4 | my $dig = shift; | |||||||||||||||||||
| 63 | 4 | require Digest::MD5; | |||||||||||||||||||
| 64 | 4 | $dig->{md} = \&Digest::MD5::md5; | |||||||||||||||||||
| 65 | 4 | $dig; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | package Crypt::OpenPGP::Digest::SHA1; | ||||||||||||||||||||
| 69 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 70 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 11 | ▶ | use parent qw( Crypt::OpenPGP::Digest ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 15 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 75 | 15 | my $dig = shift; | |||||||||||||||||||
| 76 | 15 | require Digest::SHA; | |||||||||||||||||||
| 77 | 15 | $dig->{md} = \&Digest::SHA::sha1; | |||||||||||||||||||
| 78 | 15 | $dig; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | package Crypt::OpenPGP::Digest::RIPEMD160; | ||||||||||||||||||||
| 82 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 83 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 11 | ▶ | use parent qw( Crypt::OpenPGP::Digest ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 2 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 88 | 2 | my $dig = shift; | |||||||||||||||||||
| 89 | 2 | require Crypt::RIPEMD160; | |||||||||||||||||||
| 90 | 2 | ▶ | $dig->{md} = sub { Crypt::RIPEMD160->hash($_[0]) }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 91 | 2 | $dig; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | package Crypt::OpenPGP::Digest::SHA224; | ||||||||||||||||||||
| 95 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 96 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 11 | ▶ | use parent qw( Crypt::OpenPGP::Digest ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 2 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 101 | 2 | my $dig = shift; | |||||||||||||||||||
| 102 | 2 | require Digest::SHA; | |||||||||||||||||||
| 103 | 2 | $dig->{md} = \&Digest::SHA::sha224; | |||||||||||||||||||
| 104 | 2 | $dig; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | package Crypt::OpenPGP::Digest::SHA256; | ||||||||||||||||||||
| 108 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 109 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 11 | ▶ | use parent qw( Crypt::OpenPGP::Digest ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 2 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 114 | 2 | my $dig = shift; | |||||||||||||||||||
| 115 | 2 | require Digest::SHA; | |||||||||||||||||||
| 116 | 2 | $dig->{md} = \&Digest::SHA::sha256; | |||||||||||||||||||
| 117 | 2 | $dig; | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | package Crypt::OpenPGP::Digest::SHA384; | ||||||||||||||||||||
| 121 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 122 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 11 | ▶ | use parent qw( Crypt::OpenPGP::Digest ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 2 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 127 | 2 | my $dig = shift; | |||||||||||||||||||
| 128 | 2 | require Digest::SHA; | |||||||||||||||||||
| 129 | 2 | $dig->{md} = \&Digest::SHA::sha384; | |||||||||||||||||||
| 130 | 2 | $dig; | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | package Crypt::OpenPGP::Digest::SHA512; | ||||||||||||||||||||
| 134 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 135 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 11 | ▶ | use parent qw( Crypt::OpenPGP::Digest ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 3 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 140 | 3 | my $dig = shift; | |||||||||||||||||||
| 141 | 3 | require Digest::SHA; | |||||||||||||||||||
| 142 | 3 | $dig->{md} = \&Digest::SHA::sha512; | |||||||||||||||||||
| 143 | 3 | $dig; | |||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 11 | 1; | |||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||