| 1 | package Net::Braintree::Digest; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Digest::SHA1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Digest::SHA256; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Digest::SHA qw(hmac_sha256_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Net::Braintree::DigestSHA256; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 13 | 1 | our @EXPORT = qw(hexdigest hexdigest_256); | |||||||||||||||||||||||||||
| 14 | 1 | our @EXPORT_OK = qw(); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub algo_class { | ||||||||||||||||||||||||||
|
Subroutine
algo_class: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ($algo) = @_; | |||||||||||||||||||||||||||
| 18 | 0 | ▶ | if ($algo eq "SHA-1") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | return "Digest::SHA1"; | |||||||||||||||||||||||||||
| 20 | } else { | ||||||||||||||||||||||||||||
| 21 | 0 | return "Net::Braintree::DigestSHA256"; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub hmac { | ||||||||||||||||||||||||||
|
Subroutine
hmac: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 0 | my($key, $algo) = @_; | |||||||||||||||||||||||||||
| 27 | 0 | return Digest::HMAC->new($key, algo_class($algo)); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub hexdigest { | ||||||||||||||||||||||||||
|
Subroutine
hexdigest: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | my($key, $data) = @_; | |||||||||||||||||||||||||||
| 32 | 0 | return _hexdigest($key, $data, "SHA-1"); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub hexdigest_256 { | ||||||||||||||||||||||||||
|
Subroutine
hexdigest_256: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 0 | my($key, $data) = @_; | |||||||||||||||||||||||||||
| 37 | 0 | return _hexdigest($key, $data, "SHA-256"); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _hexdigest { | ||||||||||||||||||||||||||
|
Subroutine
_hexdigest: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($key, $data, $algo) = @_; | |||||||||||||||||||||||||||
| 42 | 0 | my $digested_key = key_digest($algo, $key); | |||||||||||||||||||||||||||
| 43 | 0 | my $hmac = hmac($digested_key, $algo); | |||||||||||||||||||||||||||
| 44 | 0 | $hmac->add($data); | |||||||||||||||||||||||||||
| 45 | 0 | return $hmac->hexdigest; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub key_digest { | ||||||||||||||||||||||||||
|
Subroutine
key_digest: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 0 | my ($alg, $key) = @_; | |||||||||||||||||||||||||||
| 50 | 0 | my $sha = Digest->new($alg); | |||||||||||||||||||||||||||
| 51 | 0 | $sha->add($key); | |||||||||||||||||||||||||||
| 52 | 0 | return $sha->digest; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub secure_compare { | ||||||||||||||||||||||||||
|
Subroutine
secure_compare: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($left, $right) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ((not defined($left)) || (not defined($right))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $left and defined $right
MC/DC0%0/2
defined $left and defined $right
defined $left
defined $right
Truth table0%0/3
A and B
A= defined $leftB= defined $right
| |||||||||||||||||||||||||||||
| 59 | 0 | return 0; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | my @left_bytes = unpack("C*", $left); | |||||||||||||||||||||||||||
| 63 | 0 | my @right_bytes = unpack("C*", $right); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if (scalar(@left_bytes) != scalar(@right_bytes)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | return 0; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $result = 0; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | for (my $i = 0; $i < scalar(@left_bytes); $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $result |= $left_bytes[$i] ^ $right_bytes[$i]; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | return $result == 0; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||||||||||