20-test_enc_more.t 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
  4. #
  5. # Licensed under the Apache License 2.0 (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 bldtop_dir/;
  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 $provpath = bldtop_dir("providers");
  23. my @prov = ("-provider_path", $provpath, "-provider", "default", "-provider", "legacy");
  24. my $ciphersstatus = undef;
  25. my @ciphers =
  26. grep(! /wrap|^$|^[^-]/,
  27. (map { split /\s+/ }
  28. run(app([$cmd, "enc", "-list"]),
  29. capture => 1, statusvar => \$ciphersstatus)));
  30. plan tests => 2 + scalar @ciphers;
  31. SKIP: {
  32. skip "Problems getting ciphers...", 1 + scalar(@ciphers)
  33. unless ok($ciphersstatus, "Running 'openssl enc -list'");
  34. unless (ok(copy($testsrc, $plaintext), "Copying $testsrc to $plaintext")) {
  35. diag($!);
  36. skip "Not initialized, skipping...", scalar(@ciphers);
  37. }
  38. foreach my $cipher (@ciphers) {
  39. my $ciphername = substr $cipher, 1;
  40. my $cipherfile = "$plaintext.$ciphername.cipher";
  41. my $clearfile = "$plaintext.$ciphername.clear";
  42. my @common = ( $cmd, "enc", "$cipher", "-k", "test" );
  43. ok(run(app([@common, @prov, "-e", "-in", $plaintext, "-out", $cipherfile]))
  44. && compare_text($plaintext, $cipherfile) != 0
  45. && run(app([@common, @prov, "-d", "-in", $cipherfile, "-out", $clearfile]))
  46. && compare_text($plaintext, $clearfile) == 0
  47. , $ciphername);
  48. }
  49. }