File Coverage

blib/lib/PayProp/API/Public/Client/Role/Encrypt.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1             package PayProp::API::Public::Client::Role::Encrypt;
2              
3 4     4   352706 use strict;
  4         8  
  4         143  
4 4     4   18 use warnings;
  4         9  
  4         208  
5              
6 4     4   369 use Mouse::Role;
  4         1021  
  4         44  
7              
8 4     4   4630 use Crypt::CBC;
  4         51821  
  4         161  
9 4     4   1043 use Mojo::Promise;
  4         882139  
  4         34  
10              
11              
12             has encryption_secret => (
13             is => 'ro',
14             isa => 'Str',
15             required => 1,
16             );
17              
18             has Crypt => (
19             is => 'ro',
20             isa => 'Crypt::CBC',
21             lazy => 1,
22             default => sub {
23             my ( $self ) = @_;
24              
25             return Crypt::CBC->new(
26             -key => $self->encryption_secret,
27             -pass => $self->encryption_secret,
28             -pbkdf => 'pbkdf2',
29             -cipher => 'Cipher::AES',
30             );
31             },
32             );
33              
34             sub encrypt_hex_p {
35 1     1 1 7766 my ( $self, $to_encrypt ) = @_;
36              
37             return Mojo::Promise
38             ->new( sub {
39 1     1   73 my ( $resolve ) = @_;
40              
41 1         13 return $resolve->( $self->Crypt->encrypt_hex( $to_encrypt ) );
42             } )
43 1         27 ;
44             }
45              
46             sub decrypt_hex_p {
47 1     1 1 872691 my ( $self, $to_decrypt ) = @_;
48              
49             return Mojo::Promise
50             ->new( sub {
51 1     1   41 my ( $resolve ) = @_;
52              
53 1         2 my $decrypted_value;
54 1         3 eval { $decrypted_value = $self->Crypt->decrypt_hex( $to_decrypt ) };
  1         11  
55              
56 1         586491 return $resolve->( $decrypted_value );
57             } )
58 1         13 ;
59             }
60              
61             1;
62              
63             __END__