1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Crypt::Util;
my ( $c, $fallback_cipher );
BEGIN {
$c = Crypt::Util->new;
$fallback_cipher = eval { $c->fallback_cipher };
plan skip_all => "Couldn't load any cipher" if $@ =~ /^Couldn't load any cipher/;
plan 'no_plan';
}
my $key = $c->process_key("foo");
ok( length($key), "key has some length" );
cmp_ok( $key, "ne", "foo", "it's a digest of some sort" );
is( $c->process_key("foo", literal_key => 1), "foo", "literal key");
$c->default_use_literal_key(1);
is( $c->process_key("foo"), "foo", "literal key from defaults" );
$c->default_use_literal_key(0);
foreach my $mode ( qw/stream block CBC CFB OFB Ctr/ ) {
SKIP: {
skip "$mode not installed ($@)", 1 unless eval { $c->cipher_object( mode => $mode, key => "futz" ) };
my $ciphertext = $c->encrypt_string(
key => "moose",
string => "dancing",
mode => $mode,
);
is(
$c->decrypt_string(
key => "moose",
string => $ciphertext,
mode => $mode,
),
"dancing",
"round trip using $mode",
);
}
}
|