File: encrypt.t

package info (click to toggle)
libcrypt-util-perl 0.11-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: perl: 2,438; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (6)
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",
		);
	}
}