20-test_enc_more.t 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #! /usr/bin/env perl
  2. # Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
  3. # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  4. #
  5. # Licensed under the OpenSSL license (the "License"). You may not use
  6. # this file except in compliance with the License. You can obtain a copy
  7. # in the file LICENSE in the source distribution or at
  8. # https://www.openssl.org/source/license.html
  9. use strict;
  10. use warnings;
  11. use File::Spec::Functions qw/catfile/;
  12. use File::Copy;
  13. use File::Compare qw/compare_text/;
  14. use File::Basename;
  15. use OpenSSL::Test qw/:DEFAULT srctop_file/;
  16. setup("test_evp_more");
  17. my $testsrc = srctop_file("test", "recipes", basename($0));
  18. my $cipherlist = undef;
  19. my $plaintext = catfile(".", "testdatafile");
  20. my $fail = "";
  21. my $cmd = "openssl";
  22. my $ciphersstatus = undef;
  23. my @ciphers =
  24. grep(! /wrap|^$|^[^-]/,
  25. (map { split /\s+/ }
  26. run(app([$cmd, "enc", "-ciphers"]),
  27. capture => 1, statusvar => \$ciphersstatus)));
  28. plan tests => 2 + scalar @ciphers;
  29. SKIP: {
  30. skip "Problems getting ciphers...", 1 + scalar(@ciphers)
  31. unless ok($ciphersstatus, "Running 'openssl enc -ciphers'");
  32. unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) {
  33. diag($!);
  34. skip "Not initialized, skipping...", scalar(@ciphers);
  35. }
  36. foreach my $cipher (@ciphers) {
  37. my $ciphername = substr $cipher, 1;
  38. my $cipherfile = "$plaintext.$ciphername.cipher";
  39. my $clearfile = "$plaintext.$ciphername.clear";
  40. my @common = ( $cmd, "enc", "$cipher", "-k", "test" );
  41. ok(run(app([@common, "-e", "-in", $plaintext, "-out", $cipherfile]))
  42. && compare_text($plaintext, $cipherfile) != 0
  43. && run(app([@common, "-d", "-in", $cipherfile, "-out", $clearfile]))
  44. && compare_text($plaintext, $clearfile) == 0
  45. , $ciphername);
  46. unlink $cipherfile, $clearfile;
  47. }
  48. }
  49. unlink $plaintext;