| 1 | package Bitcoin::Crypto::Secret; | ||||||||||
| 2 | 40 | $Bitcoin::Crypto::Secret::VERSION = '4.005'; | |||||||||
| 3 | 40 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 40 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 40 | ▶ | use Scalar::Util qw(refaddr); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 40 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | use overload | ||||||||||
| 11 | 40 | ▶ | q{""} => "as_string", | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 40 | fallback => 1; | |||||||||
| 13 | |||||||||||
| 14 | 40 | my %secrets; | |||||||||
| 15 | |||||||||||
| 16 | 637 | ▶ | my $store_secret = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 637 | my ($obj, $secret) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 637 | $secrets{$obj} = $secret; | |||||||||
| 20 | 637 | return; | |||||||||
| 21 | 40 | }; | |||||||||
| 22 | |||||||||||
| 23 | 1793 | ▶ | my $retrieve_secret = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||
| 24 | 1793 | my ($obj) = @_; | |||||||||
| 25 | |||||||||||
| 26 | 1793 | ▶ | return undef unless exists $secrets{$obj}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 1793 | return $secrets{$obj}; | |||||||||
| 28 | 40 | }; | |||||||||
| 29 | |||||||||||
| 30 | 637 | ▶ | my $delete_secret = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 637 | my ($obj) = @_; | |||||||||
| 32 | |||||||||||
| 33 | 637 | delete $secrets{$obj}; | |||||||||
| 34 | 637 | return; | |||||||||
| 35 | 40 | }; | |||||||||
| 36 | |||||||||||
| 37 | sub new | ||||||||||
| 38 | 637 | ▶ | { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 39 | 637 | my ($class, $secret) = @_; | |||||||||
| 40 | |||||||||||
| 41 | 637 | my $str = '[REDACTED]'; | |||||||||
| 42 | 637 | my $self = bless \$str, $class; | |||||||||
| 43 | 637 | $store_secret->(refaddr $self, $secret); | |||||||||
| 44 | 637 | return $self; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub unmask_to | ||||||||||
| 48 | 1793 | ▶ | { | ||||||||
|
Subroutine
unmask_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | 1793 | my ($self, $sub_ref) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 1793 | return $sub_ref->($retrieve_secret->(refaddr $self)); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | sub DESTROY | ||||||||||
| 55 | 637 | ▶ | { | ||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 637 | my ($self) = @_; | |||||||||
| 57 | |||||||||||
| 58 | 637 | $delete_secret->(refaddr $self); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub as_string | ||||||||||
| 62 | 3 | ▶ | { | ||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 63 | 3 | return ${$_[0]}; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 40 | 1; | |||||||||
| 67 | |||||||||||
| 68 | __END__ | ||||||||||