]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/20-test_enc.t
Update copyright year
[thirdparty/openssl.git] / test / recipes / 20-test_enc.t
CommitLineData
596d6b7e 1#! /usr/bin/env perl
33388b44 2# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
596d6b7e 3#
909f1a2e 4# Licensed under the Apache License 2.0 (the "License"). You may not use
596d6b7e
RS
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
13350a0c
RL
9
10use strict;
11use warnings;
12
13use File::Spec::Functions qw/catfile/;
14use File::Copy;
15use File::Compare qw/compare_text/;
16use File::Basename;
f5056577 17use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir/;
13350a0c
RL
18
19setup("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.
42e0ccdf 24my $testsrc = srctop_file("test","recipes",basename($0));
13350a0c
RL
25
26my $test = catfile(".", "p");
27
28my $cmd = "openssl";
f5056577
SL
29my $provpath = bldtop_dir("providers");
30my @prov = ("-provider_path", $provpath, "-provider", "default", "-provider", "legacy");
13350a0c 31
30f1c9c4 32my $ciphersstatus = undef;
13350a0c 33my @ciphers =
85833408 34 map { s/^\s+//; s/\s+$//; split /\s+/ }
30f1c9c4
RL
35 run(app([$cmd, "list", "-cipher-commands"]),
36 capture => 1, statusvar => \$ciphersstatus);
13350a0c 37
30f1c9c4 38plan tests => 2 + (scalar @ciphers)*2;
13350a0c
RL
39
40 SKIP: {
30f1c9c4
RL
41 skip "Problems getting ciphers...", 1 + scalar(@ciphers)
42 unless ok($ciphersstatus, "Running 'openssl list -cipher-commands'");
43 unless (ok(copy($testsrc, $test), "Copying $testsrc to $test")) {
44 diag($!);
45 skip "Not initialized, skipping...", scalar(@ciphers);
46 }
13350a0c
RL
47
48 foreach my $c (@ciphers) {
49 my %variant = ("$c" => [],
50 "$c base64" => [ "-a" ]);
51
52 foreach my $t (sort keys %variant) {
53 my $cipherfile = "$test.$c.cipher";
54 my $clearfile = "$test.$c.clear";
55 my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" );
56 my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" );
57 if ($c eq "cat") {
58 $cipherfile = "$test.cipher";
59 $clearfile = "$test.clear";
60 @e = ( "enc", @{$variant{$t}}, "-e" );
61 @d = ( "enc", @{$variant{$t}}, "-d" );
62 }
63
f5056577
SL
64 ok(run(app([$cmd, @e, @prov, "-in", $test, "-out", $cipherfile]))
65 && run(app([$cmd, @d, @prov, "-in", $cipherfile, "-out", $clearfile]))
13350a0c 66 && compare_text($test,$clearfile) == 0, $t);
13350a0c
RL
67 }
68 }
69}