Debian Codegraph @

t/encrypt.t

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