]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/20-test_enc.t
Add the encryption test recipe
[thirdparty/openssl.git] / test / recipes / 20-test_enc.t
CommitLineData
13350a0c
RL
1#! /usr/bin/perl
2
3use strict;
4use warnings;
5
6use File::Spec::Functions qw/catfile/;
7use File::Copy;
8use File::Compare qw/compare_text/;
9use File::Basename;
10use Test::More;
11use OpenSSL::Test qw/:DEFAULT top_file/;
12
13setup("test_enc");
14
15# We do it this way, because setup() may have moved us around,
16# so the directory portion of $0 might not be correct any more.
17# However, the name hasn't changed.
18my $testsrc = top_file("test","recipes",basename($0));
19
20my $test = catfile(".", "p");
21
22my $cmd = "openssl";
23
24my @ciphers =
25 map { chomp; s/^\s+//; s/\s+$//; split /\s+/ }
26 run(app([$cmd, "list", "-cipher-commands"]), capture => 1);
27
28plan tests => 1 + (scalar @ciphers)*2;
29
30my $init = ok(copy($testsrc,$test));
31
32if (!$init) {
33 diag("Trying to copy $testsrc to $test : $!");
34}
35
36 SKIP: {
37 skip "Not initialized, skipping...", 11 unless $init;
38
39 foreach my $c (@ciphers) {
40 my %variant = ("$c" => [],
41 "$c base64" => [ "-a" ]);
42
43 foreach my $t (sort keys %variant) {
44 my $cipherfile = "$test.$c.cipher";
45 my $clearfile = "$test.$c.clear";
46 my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" );
47 my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" );
48 if ($c eq "cat") {
49 $cipherfile = "$test.cipher";
50 $clearfile = "$test.clear";
51 @e = ( "enc", @{$variant{$t}}, "-e" );
52 @d = ( "enc", @{$variant{$t}}, "-d" );
53 }
54
55 ok(run(app([$cmd, @e],
56 stdin => $test, stdout => $cipherfile))
57 && run(app([$cmd, @d],
58 stdin => $cipherfile, stdout => $clearfile))
59 && compare_text($test,$clearfile) == 0, $t);
60 unlink $cipherfile, $clearfile;
61 }
62 }
63}
64
65unlink $test;