20-test_enc.t 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. 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/;
  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 $ciphersstatus = undef;
  23. my @ciphers =
  24. map { s/^\s+//; s/\s+$//; split /\s+/ }
  25. run(app([$cmd, "list", "-cipher-commands"]),
  26. capture => 1, statusvar => \$ciphersstatus);
  27. plan tests => 2 + (scalar @ciphers)*2;
  28. SKIP: {
  29. skip "Problems getting ciphers...", 1 + scalar(@ciphers)
  30. unless ok($ciphersstatus, "Running 'openssl list -cipher-commands'");
  31. unless (ok(copy($testsrc, $test), "Copying $testsrc to $test")) {
  32. diag($!);
  33. skip "Not initialized, skipping...", scalar(@ciphers);
  34. }
  35. foreach my $c (@ciphers) {
  36. my %variant = ("$c" => [],
  37. "$c base64" => [ "-a" ]);
  38. foreach my $t (sort keys %variant) {
  39. my $cipherfile = "$test.$c.cipher";
  40. my $clearfile = "$test.$c.clear";
  41. my @e = ( "$c", "-bufsize", "113", @{$variant{$t}}, "-e", "-k", "test" );
  42. my @d = ( "$c", "-bufsize", "157", @{$variant{$t}}, "-d", "-k", "test" );
  43. if ($c eq "cat") {
  44. $cipherfile = "$test.cipher";
  45. $clearfile = "$test.clear";
  46. @e = ( "enc", @{$variant{$t}}, "-e" );
  47. @d = ( "enc", @{$variant{$t}}, "-d" );
  48. }
  49. ok(run(app([$cmd, @e, "-in", $test, "-out", $cipherfile]))
  50. && run(app([$cmd, @d, "-in", $cipherfile, "-out", $clearfile]))
  51. && compare_text($test,$clearfile) == 0, $t);
  52. unlink $cipherfile, $clearfile;
  53. }
  54. }
  55. }
  56. unlink $test;