scratch/x.pl
branchtesting
changeset 37 cb50d6c57439
child 57 e91f117472ed
equal deleted inserted replaced
36:f361d688365c 37:cb50d6c57439
       
     1 #!/usr/bin/perl
       
     2 use 5.010;
       
     3 use strict;
       
     4 use warnings;
       
     5 use Crypt::CBC;
       
     6 use autodie qw(:all);
       
     7 use Benchmark qw(:all);
       
     8 use IO::Compress::Gzip qw(gzip $GzipError);
       
     9 use File::Temp;
       
    10 
       
    11 my $tmp = File::Temp->new();
       
    12 warn "<< $tmp >>\n";
       
    13 
       
    14 my $cipher0 = Crypt::CBC->new(
       
    15     -key => "x",
       
    16     -keysize => 16,
       
    17     -cipher => 'Blowfish',
       
    18 ) or die;
       
    19 $ENV{X} = "x";
       
    20 
       
    21 @ARGV = qw(/boot/vmlinuz-2.6.32-5-amd64);
       
    22 my $text = join "" => <>;
       
    23 
       
    24 say length $text;
       
    25 
       
    26 cmpthese(30 => {
       
    27     'openssl' => sub { openssl($text) },
       
    28     'perlssl' => sub { perlssl($text) },
       
    29     }
       
    30 );
       
    31 
       
    32 cmpthese(30 => {
       
    33     'gzip' => sub { bingzip($text) },
       
    34     'perlzip' => sub { perlzip($text) },
       
    35     }
       
    36 );
       
    37 
       
    38 sub openssl {
       
    39     open(my $out, "|openssl bf -pass env:X -out $tmp") or die;
       
    40     print $out $_[0];
       
    41     close $out;
       
    42     die $? if $?;
       
    43 }
       
    44 
       
    45 sub perlssl {
       
    46     open(my $out, ">$tmp");
       
    47     print $out $cipher0->encrypt($_[0]);
       
    48     close $out;
       
    49 }
       
    50 
       
    51 sub perlzip {
       
    52     open(my $out, ">$tmp");
       
    53     gzip($_[0] => $out);
       
    54 }
       
    55 
       
    56 sub bingzip {
       
    57     open(my $out, "|gzip -1 >$tmp");
       
    58     print $out $_[0];
       
    59     close $out;
       
    60     die $? if $?
       
    61 }