123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- use strict;
- use warnings;
- use File::Compare qw/compare_text/;
- use File::Copy;
- use OpenSSL::Test qw/:DEFAULT/;
- my %conversionforms = (
-
-
- "*" => [ "d", "p" ],
- "msb" => [ "d", "p", "msblob" ],
- );
- sub tconversion {
- my $testtype = shift;
- my $t = shift;
- my @conversionforms =
- defined($conversionforms{$testtype}) ?
- @{$conversionforms{$testtype}} :
- @{$conversionforms{"*"}};
- my @openssl_args = @_;
- if (!@openssl_args) { @openssl_args = ($testtype); }
- my $n = scalar @conversionforms;
- my $totaltests =
- 1
- + $n
- + $n*$n
- + 1
- + $n*($n-1);
- $totaltests-- if ($testtype eq "p7d");
- plan tests => $totaltests;
- my @cmd = ("openssl", @openssl_args);
- my $init;
- if (scalar @openssl_args > 0 && $openssl_args[0] eq "pkey") {
- $init = ok(run(app([@cmd, "-in", $t, "-out", "$testtype-fff.p"])),
- 'initializing');
- } else {
- $init = ok(copy($t, "$testtype-fff.p"), 'initializing');
- }
- if (!$init) {
- diag("Trying to copy $t to $testtype-fff.p : $!");
- }
- SKIP: {
- skip "Not initialized, skipping...", 22 unless $init;
- foreach my $to (@conversionforms) {
- ok(run(app([@cmd,
- "-in", "$testtype-fff.p",
- "-inform", "p",
- "-out", "$testtype-f.$to",
- "-outform", $to])),
- "p -> $to");
- }
- foreach my $to (@conversionforms) {
- foreach my $from (@conversionforms) {
- ok(run(app([@cmd,
- "-in", "$testtype-f.$from",
- "-inform", $from,
- "-out", "$testtype-ff.$from$to",
- "-outform", $to])),
- "$from -> $to");
- }
- }
- if ($testtype ne "p7d") {
- is(cmp_text("$testtype-fff.p", "$testtype-f.p"), 0,
- 'comparing orig to p');
- }
- foreach my $to (@conversionforms) {
- next if $to eq "d";
- foreach my $from (@conversionforms) {
- is(cmp_text("$testtype-f.$to", "$testtype-ff.$from$to"), 0,
- "comparing $to to $from$to");
- }
- }
- }
- unlink glob "$testtype-f.*";
- unlink glob "$testtype-ff.*";
- unlink glob "$testtype-fff.*";
- }
- sub cmp_text {
- return compare_text(@_, sub {
- $_[0] =~ s/\R//g;
- $_[1] =~ s/\R//g;
- return $_[0] ne $_[1];
- });
- }
- 1;
|