20-test_enc.t 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #! /usr/bin/env perl
  2. # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (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. use strict;
  9. use warnings;
  10. use File::Spec::Functions qw/catfile/;
  11. use File::Copy;
  12. use File::Compare qw/compare_text/;
  13. use File::Basename;
  14. use OpenSSL::Test qw/:DEFAULT srctop_file bldtop_dir/;
  15. setup("test_enc");
  16. # We do it this way, because setup() may have moved us around,
  17. # so the directory portion of $0 might not be correct any more.
  18. # However, the name hasn't changed.
  19. my $testsrc = srctop_file("test","recipes",basename($0));
  20. my $test = catfile(".", "p");
  21. my $cmd = "openssl";
  22. my $provpath = bldtop_dir("providers");
  23. my @prov = ("-provider_path", $provpath, "-provider", "default", "-provider", "legacy");
  24. my $ciphersstatus = undef;
  25. my @ciphers =
  26. map { s/^\s+//; s/\s+$//; split /\s+/ }
  27. run(app([$cmd, "list", "-cipher-commands"]),
  28. capture => 1, statusvar => \$ciphersstatus);
  29. plan tests => 2 + (scalar @ciphers)*2;
  30. SKIP: {
  31. skip "Problems getting ciphers...", 1 + scalar(@ciphers)
  32. unless ok($ciphersstatus, "Running 'openssl list -cipher-commands'");
  33. unless (ok(copy($testsrc, $test), "Copying $testsrc to $test")) {
  34. diag($!);
  35. skip "Not initialized, skipping...", scalar(@ciphers);
  36. }
  37. foreach my $c (@ciphers) {
  38. my %variant = ("$c" => [],
  39. "$c base64" => [ "-a" ]);
  40. foreach my $t (sort keys %variant) {
  41. my $cipherfile = "$test.$c.cipher";
  42. my $clearfile = "$test.$c.clear";
  43. my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" );
  44. my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" );
  45. if ($c eq "cat") {
  46. $cipherfile = "$test.cipher";
  47. $clearfile = "$test.clear";
  48. @e = ( "enc", @{$variant{$t}}, "-e" );
  49. @d = ( "enc", @{$variant{$t}}, "-d" );
  50. }
  51. ok(run(app([$cmd, @e, @prov, "-in", $test, "-out", $cipherfile]))
  52. && run(app([$cmd, @d, @prov, "-in", $cipherfile, "-out", $clearfile]))
  53. && compare_text($test,$clearfile) == 0, $t);
  54. }
  55. }
  56. }