Remove more redundant tests: md4, md5, rmd, rc4, p5_crpt2
[openssl.git] / test / recipes / 20-test_enc.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9
10 use strict;
11 use warnings;
12
13 use File::Spec::Functions qw/catfile/;
14 use File::Copy;
15 use File::Compare qw/compare_text/;
16 use File::Basename;
17 use OpenSSL::Test qw/:DEFAULT srctop_file/;
18
19 setup("test_enc");
20
21 # We do it this way, because setup() may have moved us around,
22 # so the directory portion of $0 might not be correct any more.
23 # However, the name hasn't changed.
24 my $testsrc = srctop_file("test","recipes",basename($0));
25
26 my $test = catfile(".", "p");
27
28 my $cmd = "openssl";
29
30 my @ciphers =
31     map { s/^\s+//; s/\s+$//; split /\s+/ }
32     run(app([$cmd, "list", "-cipher-commands"]), capture => 1);
33
34 plan tests => 1 + (scalar @ciphers)*2;
35
36 my $init = ok(copy($testsrc,$test));
37
38 if (!$init) {
39     diag("Trying to copy $testsrc to $test : $!");
40 }
41
42  SKIP: {
43      skip "Not initialized, skipping...", 11 unless $init;
44
45      foreach my $c (@ciphers) {
46          my %variant = ("$c" => [],
47                         "$c base64" => [ "-a" ]);
48
49          foreach my $t (sort keys %variant) {
50              my $cipherfile = "$test.$c.cipher";
51              my $clearfile = "$test.$c.clear";
52              my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" );
53              my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" );
54              if ($c eq "cat") {
55                  $cipherfile = "$test.cipher";
56                  $clearfile = "$test.clear";
57                  @e = ( "enc", @{$variant{$t}}, "-e" );
58                  @d = ( "enc", @{$variant{$t}}, "-d" );
59              }
60
61              ok(run(app([$cmd, @e, "-in", $test, "-out", $cipherfile]))
62                 && run(app([$cmd, @d, "-in", $cipherfile, "-out", $clearfile]))
63                 && compare_text($test,$clearfile) == 0, $t);
64              unlink $cipherfile, $clearfile;
65          }
66      }
67 }
68
69 unlink $test;