File Coverage

blib/lib/Net/SSH/Perl/Cipher/AES_CTR.pm
Criterion Covered Total %
statement 28 29 96.5
branch 1 2 50.0
condition n/a
subroutine 9 11 81.8
pod 3 6 50.0
total 41 48 85.4


line stmt bran cond sub pod time code
1             package Net::SSH::Perl::Cipher::AES_CTR;
2              
3 1     1   16 use strict;
  1         1  
  1         30  
4              
5 1     1   9 use Net::SSH::Perl::Cipher;
  1         2  
  1         25  
6 1     1   4 use base qw( Net::SSH::Perl::Cipher );
  1         11  
  1         126  
7              
8 1     1   503 use Net::SSH::Perl::Cipher::CTR;
  1         3  
  1         30  
9 1     1   6 use Crypt::Cipher::AES;
  1         2  
  1         231  
10              
11             sub new {
12 6     6 1 16 my $class = shift;
13 6         19 my $ciph = bless { }, $class;
14 6 50       39 $ciph->init(@_) if @_;
15 6         17 $ciph;
16             }
17              
18       0 0   sub keysize { } # stub
19 0     0 0 0 sub blocksize { 16 } # 128 bits as required by AES
20              
21             sub init {
22 6     6 0 11 my $ciph = shift;
23 6         18 my($key, $iv) = @_;
24              
25 6         32 $key = substr($key,0,$ciph->keysize);
26 6         108 my $aes = Crypt::Cipher::AES->new($key);
27 6         44 $ciph->{ctr} = Net::SSH::Perl::Cipher::CTR->new($aes, $iv);
28             }
29              
30             sub encrypt {
31 3     3 1 3082 my($ciph, $text) = @_;
32 3         16 return $ciph->{ctr}->encrypt($text);
33             }
34              
35             sub decrypt {
36 3     3 1 17 my($ciph, $text) = @_;
37 3         10 return $ciph->{ctr}->decrypt($text);
38             }
39              
40             1;
41             __END__