| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IO::Stream::Crypt::RC4; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 41171 | use warnings; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 69 |  | 
| 4 | 2 |  |  | 2 |  | 10 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 5 | 2 |  |  | 2 |  | 10 | use Carp; | 
|  | 2 |  |  |  |  | 8 |  | 
|  | 2 |  |  |  |  | 155 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 1647 | use version; our $VERSION = qv('1.0.3');    # update POD & Changes & README | 
|  | 2 |  |  |  |  | 4418 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | # update DEPENDENCIES in POD & Makefile.PL & README | 
| 10 | 2 |  |  | 2 |  | 1109 | use IO::Stream::const; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | use Crypt::RC4; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub new { | 
| 15 |  |  |  |  |  |  | my ($class, $passphrase) = @_; | 
| 16 |  |  |  |  |  |  | croak 'usage: IO::Stream::Crypt::RC4->new("passphrase")' | 
| 17 |  |  |  |  |  |  | if !defined $passphrase; | 
| 18 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | return $self; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | sub PREPARE { | 
| 33 |  |  |  |  |  |  | my ($self, $fh, $host, $port) = @_; | 
| 34 |  |  |  |  |  |  | $self->{_slave}->PREPARE($fh, $host, $port); | 
| 35 |  |  |  |  |  |  | return; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub WRITE { | 
| 39 |  |  |  |  |  |  | my ($self) = @_; | 
| 40 |  |  |  |  |  |  | my $m = $self->{_master}; | 
| 41 |  |  |  |  |  |  | my $s = substr $m->{out_buf}, $m->{out_pos}||0; | 
| 42 |  |  |  |  |  |  | my $n = length $s; | 
| 43 |  |  |  |  |  |  | $self->{out_buf} .= $self->{_wcrypt}->RC4($s); | 
| 44 |  |  |  |  |  |  | if (defined $m->{out_pos}) { | 
| 45 |  |  |  |  |  |  | $m->{out_pos} += $n; | 
| 46 |  |  |  |  |  |  | } else { | 
| 47 |  |  |  |  |  |  | $m->{out_buf} = q{}; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  | $m->{out_bytes} += $n; | 
| 50 |  |  |  |  |  |  | $m->EVENT(OUT); | 
| 51 |  |  |  |  |  |  | $self->{_slave}->WRITE(); | 
| 52 |  |  |  |  |  |  | return; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub EVENT { | 
| 56 |  |  |  |  |  |  | my ($self, $e, $err) = @_; | 
| 57 |  |  |  |  |  |  | my $m = $self->{_master}; | 
| 58 |  |  |  |  |  |  | if ($e & OUT) { | 
| 59 |  |  |  |  |  |  | $e &= ~OUT; | 
| 60 |  |  |  |  |  |  | return if !$e && !$err; | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | if ($e & IN) { | 
| 63 |  |  |  |  |  |  | $m->{in_buf}    .= $self->{_rcrypt}->RC4($self->{in_buf}); | 
| 64 |  |  |  |  |  |  | $m->{in_bytes}  += $self->{in_bytes}; | 
| 65 |  |  |  |  |  |  | $self->{in_buf}  = q{}; | 
| 66 |  |  |  |  |  |  | $self->{in_bytes}= 0; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | if ($e & RESOLVED) { | 
| 69 |  |  |  |  |  |  | $m->{ip} = $self->{ip}; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  | if ($e & EOF) { | 
| 72 |  |  |  |  |  |  | $m->{is_eof} = $self->{is_eof}; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  | $m->EVENT($e, $err); | 
| 75 |  |  |  |  |  |  | return; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | 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. |