File Coverage

blib/lib/Crypt/Stream/RC4.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 14 100.0


line stmt bran cond sub pod time code
1             package Crypt::Stream::RC4;
2              
3 3     3   94869 use strict;
  3         6  
  3         124  
4 3     3   57 use warnings;
  3         24  
  3         225  
5             our $VERSION = '0.089';
6              
7 3     3   627 use CryptX;
  3         6  
  3         202  
8              
9 1     1   2933 sub CLONE_SKIP { 1 } # prevent cloning
10              
11             1;
12              
13             =pod
14              
15             =head1 NAME
16              
17             Crypt::Stream::RC4 - Stream cipher RC4
18              
19             =head1 SYNOPSIS
20              
21             use Crypt::Stream::RC4;
22              
23             # encrypt
24             my $key = "1234567890123456";
25             my $enc_stream = Crypt::Stream::RC4->new($key);
26             my $ct = $enc_stream->crypt("plain message");
27              
28             # decrypt
29             my $dec_stream = Crypt::Stream::RC4->new($key);
30             my $pt = $dec_stream->crypt($ct);
31              
32             =head1 DESCRIPTION
33              
34             Provides an interface to the RC4 stream cipher.
35              
36             =head1 METHODS
37              
38             Unless noted otherwise, assume C<$stream> is an existing stream object created
39             via C, for example:
40              
41             my $stream = Crypt::Stream::RC4->new($key);
42              
43             =head2 new
44              
45             my $stream = Crypt::Stream::RC4->new($key);
46             # $key .. [binary string] length 5-256 bytes (40 - 2048 bits)
47              
48             =head2 crypt
49              
50             Encrypts or decrypts data. The output has the same length as the input.
51             Returns a binary string (raw bytes).
52              
53             The input is converted using Perl's usual scalar stringification. Passing
54             C is treated as an empty string with the usual warning, and numeric
55             scalars are stringified before processing.
56              
57             my $ciphertext = $stream->crypt($plaintext);
58             #or
59             my $plaintext = $stream->crypt($ciphertext);
60              
61             =head2 keystream
62              
63             Returns C<$length> bytes of raw keystream as a binary string.
64              
65             The length is taken using Perl's usual numeric coercion. Values that coerce to
66             an oversized unsigned length are rejected as too large.
67              
68             my $random_key = $stream->keystream($length);
69              
70             =head2 clone
71              
72             Returns a copy of the stream cipher object in its current state.
73              
74             my $stream2 = $stream->clone();
75              
76             =head1 SEE ALSO
77              
78             =over
79              
80             =item * L, L, L, L
81              
82             =item * L
83              
84             =back
85              
86             =cut