summaryrefslogtreecommitdiffstats
path: root/libtests/qtest/rc4.test
blob: e718478bd0d3c29e03c4f7bfb14f340cbfd47036 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
require 5.008;
BEGIN { $^W = 1; }
use strict;

chdir("rc4") or die "chdir testdir failed: $!\n";

require TestDriver;

my $td = new TestDriver('RC4');

my @providers = ();
if (exists $ENV{'QPDF_CRYPTO_PROVIDER'})
{
    push(@providers, $ENV{'QPDF_CRYPTO_PROVIDER'});
}
else
{
    open(Q, "qpdf --show-crypto|") or die;
    while (<Q>)
    {
        s/\s+$//s;
        push(@providers, $_);
    }
    close(Q);
}
my @tests = ('0123456789abcdef',
             '0123456789abcdef',
             '0000000000000000',
             'ef012345',
             '0123456789abcdef');

foreach my $p (@providers)
{
    $ENV{'QPDF_CRYPTO_PROVIDER'} = $p;

    cleanup();

    my $n = 0;
    foreach my $key (@tests)
    {
        ++$n;
        $td->runtest("test $n ($p)",
                     {$td->COMMAND => "rc4 $key test$n.in tmp1-$n.out"},
                     {$td->STRING => "", $td->EXIT_STATUS => 0});
        $td->runtest("check output",
                     {$td->FILE => "tmp1-$n.out"},
                     {$td->FILE => "test$n.out"});
        $td->runtest("test $n reverse ($p)",
                     {$td->COMMAND => "rc4 $key test$n.out tmp2-$n.out"},
                     {$td->STRING => "", $td->EXIT_STATUS => 0});
        $td->runtest("check output",
                     {$td->FILE => "tmp2-$n.out"},
                     {$td->FILE => "test$n.in"});
    }

    $td->runtest("other tests ($p)",
                 {$td->COMMAND => "rc4 other"},
                 {$td->STRING => "passed\n", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);

    cleanup();
}

$td->report((1 + (4 * scalar(@tests))) * scalar(@providers));

sub cleanup
{
    system("rm -f tmp*-*");
}