« lib/WebService/Braintree/Result.pm
↑ Summary
lib/WebService/Braintree/_/Transaction/CreditCardDetail.pm »
| 1 | # vim: sw=4 ts=4 ft=perl | ||||||||||
| 2 | |||||||||||
| 3 | package # hide from pause | ||||||||||
| 4 | WebService::Braintree::Digest; | ||||||||||
| 5 | |||||||||||
| 6 | 23 | ▶ | use 5.010_001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 23 | ▶ | use strictures 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 23 | ▶ | use Carp qw(confess); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 23 | ▶ | use Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 23 | ▶ | use Digest; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 23 | ▶ | use Digest::SHA; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 23 | ▶ | use Digest::SHA1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 23 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 23 | our @ISA = qw(Exporter); | |||||||||
| 18 | 23 | our @EXPORT_OK = qw(hexdigest); | |||||||||
| 19 | |||||||||||
| 20 | 46 | ▶ | sub hexdigest { | ||||||||
|
Subroutine
hexdigest: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 21 | 46 | my($key, $data) = @_; | |||||||||
| 22 | 46 | return _hexdigest($key, $data, "SHA-1"); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | # Methods below here are only used within this class. | ||||||||||
| 26 | |||||||||||
| 27 | 46 | ▶ | sub algo_class { | ||||||||
|
Subroutine
algo_class: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||
| 28 | 46 | my ($algo) = @_; | |||||||||
| 29 | 46 | ▶ | if ($algo eq "SHA-1") { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 46 | return "Digest::SHA1"; | |||||||||
| 31 | } | ||||||||||
| 32 | 0 | confess "Unhandled algorithm '$algo'"; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 46 | ▶ | sub hmac { | ||||||||
|
Subroutine
hmac: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | 46 | my($key, $algo) = @_; | |||||||||
| 37 | 46 | return Digest::HMAC->new($key, algo_class($algo)); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 46 | ▶ | sub _hexdigest { | ||||||||
|
Subroutine
_hexdigest: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 46 | my ($key, $data, $algo) = @_; | |||||||||
| 42 | 46 | my $digested_key = key_digest($algo, $key); | |||||||||
| 43 | 46 | my $hmac = hmac($digested_key, $algo); | |||||||||
| 44 | 46 | $hmac->add($data); | |||||||||
| 45 | 46 | return $hmac->hexdigest; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 46 | ▶ | sub key_digest { | ||||||||
|
Subroutine
key_digest: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 49 | 46 | my ($alg, $key) = @_; | |||||||||
| 50 | 46 | my $sha = Digest->new($alg); | |||||||||
| 51 | 46 | $sha->add($key); | |||||||||
| 52 | 46 | return $sha->digest; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 23 | 1; | |||||||||
| 56 | __END__ | ||||||||||