| 1 | package IO::Stream::Crypt::RC4; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use version; our $VERSION = qv('1.0.3'); # update POD & Changes & README | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # update DEPENDENCIES in POD & Makefile.PL & README | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use IO::Stream::const; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Crypt::RC4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||
| 15 | 2 | ▶ | my ($class, $passphrase) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | croak 'usage: IO::Stream::Crypt::RC4->new("passphrase")' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | if !defined $passphrase; | ||||||||||||||||||||||||||||
| 18 | 2 | my $self = bless { | |||||||||||||||||||||||||||
| 19 | out_buf => q{}, # modified on: OUT | ||||||||||||||||||||||||||||
| 20 | out_pos => undef, # modified on: OUT | ||||||||||||||||||||||||||||
| 21 | out_bytes => 0, # modified on: OUT | ||||||||||||||||||||||||||||
| 22 | in_buf => q{}, # modified on: IN | ||||||||||||||||||||||||||||
| 23 | in_bytes => 0, # modified on: IN | ||||||||||||||||||||||||||||
| 24 | ip => undef, # modified on: RESOLVED | ||||||||||||||||||||||||||||
| 25 | is_eof => undef, # modified on: EOF | ||||||||||||||||||||||||||||
| 26 | _rcrypt => Crypt::RC4->new($passphrase), | ||||||||||||||||||||||||||||
| 27 | _wcrypt => Crypt::RC4->new($passphrase), | ||||||||||||||||||||||||||||
| 28 | }, $class; | ||||||||||||||||||||||||||||
| 29 | 2 | return $self; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub PREPARE { | ||||||||||||||||||||||||||||
| 33 | 2 | ▶ | my ($self, $fh, $host, $port) = @_; | ||||||||||||||||||||||||||
|
Subroutine
PREPARE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 2 | $self->{_slave}->PREPARE($fh, $host, $port); | |||||||||||||||||||||||||||
| 35 | 2 | return; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub WRITE { | ||||||||||||||||||||||||||||
| 39 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
WRITE: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 40 | 5 | my $m = $self->{_master}; | |||||||||||||||||||||||||||
| 41 | 5 | ▶ | my $s = substr $m->{out_buf}, $m->{out_pos}||0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$m->{'out_pos'} || 0
MC/DC0%0/1
$m->{'out_pos'} || 0
$m->{'out_pos'}
Truth table50%1/2
A
A= $m->{'out_pos'}
| |||||||||||||||||||||||||||||
| 42 | 5 | my $n = length $s; | |||||||||||||||||||||||||||
| 43 | 5 | $self->{out_buf} .= $self->{_wcrypt}->RC4($s); | |||||||||||||||||||||||||||
| 44 | 5 | ▶ | if (defined $m->{out_pos}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | $m->{out_pos} += $n; | |||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | 5 | $m->{out_buf} = q{}; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 5 | $m->{out_bytes} += $n; | |||||||||||||||||||||||||||
| 50 | 5 | $m->EVENT(OUT); | |||||||||||||||||||||||||||
| 51 | 5 | $self->{_slave}->WRITE(); | |||||||||||||||||||||||||||
| 52 | 5 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub EVENT { | ||||||||||||||||||||||||||||
| 56 | 158 | ▶ | my ($self, $e, $err) = @_; | ||||||||||||||||||||||||||
|
Subroutine
EVENT: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 158 | my $m = $self->{_master}; | |||||||||||||||||||||||||||
| 58 | 158 | ▶ | if ($e & OUT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 77 | $e &= ~OUT; | |||||||||||||||||||||||||||
| 60 | 77 | ▶ | return if !$e && !$err; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$e or $err
MC/DC50%1/2
$e or $err
$e
$err
Truth table66%2/3
A or B
A= $eB= $err
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 86 | ▶ | if ($e & IN) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 77 | $m->{in_buf} .= $self->{_rcrypt}->RC4($self->{in_buf}); | |||||||||||||||||||||||||||
| 64 | 77 | $m->{in_bytes} += $self->{in_bytes}; | |||||||||||||||||||||||||||
| 65 | 77 | $self->{in_buf} = q{}; | |||||||||||||||||||||||||||
| 66 | 77 | $self->{in_bytes}= 0; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 86 | ▶ | if ($e & RESOLVED) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 1 | $m->{ip} = $self->{ip}; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 86 | ▶ | if ($e & EOF) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 2 | $m->{is_eof} = $self->{is_eof}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 86 | $m->EVENT($e, $err); | |||||||||||||||||||||||||||
| 75 | 85 | return; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 3 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 NAME | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | IO::Stream::Crypt::RC4 - Crypt::RC4 plugin for IO::Stream | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 VERSION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | This document describes IO::Stream::Crypt::RC4 version 1.0.3 | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | use IO::Stream; | ||||||||||||||||||||||||||||
| 95 | use IO::Stream::Crypt::RC4; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | IO::Stream->new({ | ||||||||||||||||||||||||||||
| 98 | ... | ||||||||||||||||||||||||||||
| 99 | plugin => [ | ||||||||||||||||||||||||||||
| 100 | ... | ||||||||||||||||||||||||||||
| 101 | rc4 => IO::Stream::Crypt::RC4->new($passphrase), | ||||||||||||||||||||||||||||
| 102 | ... | ||||||||||||||||||||||||||||
| 103 | ], | ||||||||||||||||||||||||||||
| 104 | }); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | This module is plugin for L<IO::Stream> which allow you to encrypt all | ||||||||||||||||||||||||||||
| 109 | data read/written by this stream using RC4. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head1 INTERFACE | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =over | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item new($passphrase) | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Create and return new IO::Stream plugin object. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =back | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =over | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =item C<< usage: IO::Stream::Crypt::RC4->new("passphrase") >> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | You probably called new() without $passphrase parameter. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =back | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | IO::Stream::Crypt::RC4 requires no configuration files or environment variables. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | L<IO::Stream>, | ||||||||||||||||||||||||||||
| 142 | L<Crypt::RC4>. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 INCOMPATIBILITIES | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | None reported. | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | No bugs have been reported. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | Please report any bugs or feature requests to author, or | ||||||||||||||||||||||||||||
| 155 | C<bug-io-stream-crypt-rc4@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 156 | L<http://rt.cpan.org>. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Alex Efros C<< <powerman-asdf@ya.ru> >> | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Copyright (c) 2008, Alex Efros C<< <powerman-asdf@ya.ru> >>. All rights reserved. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 169 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head1 DISCLAIMER OF WARRANTY | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||||||||||||||||||||||||||||
| 175 | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | ||||||||||||||||||||||||||||
| 176 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | ||||||||||||||||||||||||||||
| 177 | PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER | ||||||||||||||||||||||||||||
| 178 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||||||||||||||||||||||||||||
| 179 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE | ||||||||||||||||||||||||||||
| 180 | ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH | ||||||||||||||||||||||||||||
| 181 | YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL | ||||||||||||||||||||||||||||
| 182 | NECESSARY SERVICING, REPAIR, OR CORRECTION. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||||||||||||||||||||||||||||
| 185 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||||||||||||||||||||||||||||
| 186 | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE | ||||||||||||||||||||||||||||
| 187 | LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, | ||||||||||||||||||||||||||||
| 188 | OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE | ||||||||||||||||||||||||||||
| 189 | THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING | ||||||||||||||||||||||||||||
| 190 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A | ||||||||||||||||||||||||||||
| 191 | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | ||||||||||||||||||||||||||||
| 192 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | ||||||||||||||||||||||||||||
| 193 | SUCH DAMAGES. | ||||||||||||||||||||||||||||