File Coverage

blib/lib/Protocol/TLS/Crypto.pm
Criterion Covered Total %
statement 16 16 100.0
branch 2 4 50.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 22 25 88.0


line stmt bran cond sub pod time code
1             package Protocol::TLS::Crypto;
2 2     2   9 use strict;
  2         4  
  2         51  
3 2     2   8 use warnings;
  2         4  
  2         57  
4 2     2   10 use Module::Runtime qw(compose_module_name require_module);
  2         3  
  2         10  
5              
6             # TODO: select backend
7             our $BACKEND = 'CryptX';
8              
9             my $crypto = undef;
10             my @methods = (qw(PRF PRF_hash random rsa_encrypt cert_pubkey));
11              
12             sub new {
13 4 50   4 0 15 return $crypto if $crypto;
14 4         30 my $module = compose_module_name( 'Protocol::TLS::Crypto', $BACKEND );
15 4         480 require_module $module;
16 4         102 my $crypto = $module->new;
17 4         21 for (@methods) {
18 20 50       126 die ref($crypto) . " backend doesn't implement method $_\n"
19             unless $crypto->can($_);
20             }
21 4         126 $crypto;
22             }
23              
24             1