File Coverage

blib/lib/Crypt/Rabbit.pm
Criterion Covered Total %
statement 18 20 90.0
branch n/a
condition n/a
subroutine 4 6 66.6
pod 3 4 75.0
total 25 30 83.3


line stmt bran cond sub pod time code
1             package Crypt::Rabbit;
2              
3 4     4   1249176 use strict;
  4         9  
  4         171  
4 4     4   25 use warnings;
  4         11  
  4         1371  
5             require Exporter;
6              
7             our @EXPORT_OK = qw(new encrypt decrypt keysize rounds);
8             our $VERSION = '1.0.0';
9             our @ISA = qw(Exporter);
10              
11             require XSLoader;
12             XSLoader::load('Crypt::Rabbit', $VERSION);
13              
14             # Preloaded methods go here.
15              
16 0     0 1 0 sub keysize { 16 } # 16 bytes
17 0     0 0 0 sub rounds { 1 } # may be useful for some applications
18              
19             sub encrypt {
20 2     2 1 7512 my ($class, $str) = @_;
21 2         7 my $len = length $str;
22 2         14 my $pad = pack "a" x ((16 - ($len % 16)) % 16), \000;
23 2         5 $str .= $pad;
24 2         16 my $ciphertext = rabbit_enc($class, $str);
25 2         10 return substr($ciphertext, 0, $len);
26             }
27              
28             sub decrypt {
29 1     1 1 3155 my ($class, $str) = @_;
30 1         3 my $len = length $str;
31 1         6 my $pad = pack "a" x ((16 - ($len % 16)) % 16), \000;
32 1         2 $str .= $pad;
33 1         6 my $ciphertext = rabbit_enc($class, $str);
34 1         4 return substr($ciphertext, 0, $len);
35             }
36              
37             1;
38              
39             __END__