]>
Commit | Line | Data |
---|---|---|
13350a0c RL |
1 | #! /usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use File::Spec::Functions qw/catfile/; | |
7 | use File::Copy; | |
8 | use File::Compare qw/compare_text/; | |
9 | use File::Basename; | |
10 | use Test::More; | |
11 | use OpenSSL::Test qw/:DEFAULT top_file/; | |
12 | ||
13 | setup("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. | |
18 | my $testsrc = top_file("test","recipes",basename($0)); | |
19 | ||
20 | my $test = catfile(".", "p"); | |
21 | ||
22 | my $cmd = "openssl"; | |
23 | ||
24 | my @ciphers = | |
25 | map { chomp; s/^\s+//; s/\s+$//; split /\s+/ } | |
26 | run(app([$cmd, "list", "-cipher-commands"]), capture => 1); | |
27 | ||
28 | plan tests => 1 + (scalar @ciphers)*2; | |
29 | ||
30 | my $init = ok(copy($testsrc,$test)); | |
31 | ||
32 | if (!$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 | ||
65 | unlink $test; |