summaryrefslogtreecommitdiff
path: root/t/decrypt.t
blob: 2d6740cfc60f386d5a2f533a6d3efa7a517fafcc (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w
#
# $Id: decrypt.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $
#

use strict;
use English qw( -no_match_vars );
use File::Compare;
use version;

use lib './t';
use MyTest;
use MyTestSpecific;

my $compare;

my $gnupg_version = version->parse($gnupg->version);

TEST
{
    reset_handles();

    my $pid = $gnupg->decrypt( handles => $handles );

    print $stdin @{ $texts{encrypted}->data() };
    close $stdin;

    $compare = compare( $texts{plain}->fn(), $stdout );
    close $stdout;
    waitpid $pid, 0;

    if ($gnupg_version < version->parse('2.2.8')) {
        return $CHILD_ERROR == 0;;
    } else {
        local $/ = undef;
        my $errstr = <$stderr>;
        return (($CHILD_ERROR >> 8 == 2) and ($errstr =~ /ignore-mdc-error/));
    }
};


TEST
{
    return $compare == 0;
};


TEST
{
    reset_handles();

    $handles->stdin( $texts{encrypted}->fh() );
    $handles->options( 'stdin' )->{direct} = 1;

    $handles->stdout( $texts{temp}->fh() );
    $handles->options( 'stdout' )->{direct} = 1;

    my $pid = $gnupg->decrypt( handles => $handles );

    waitpid $pid, 0;

    if ($gnupg_version < version->parse('2.2.8')) {
        return $CHILD_ERROR == 0;
    } else {
        local $/ = undef;
        my $errstr = <$stderr>;
        return (($CHILD_ERROR >> 8 == 2) and ($errstr =~ /ignore-mdc-error/));
    }
};


TEST
{
    return compare( $texts{plain}->fn(), $texts{temp}->fn() ) == 0;
};


# test without default_passphrase (that is, by using the agent)
TEST
{
    reset_handles();

    $handles->stdin( $texts{alt_encrypted}->fh() );
    $handles->options( 'stdin' )->{direct} = 1;

    $handles->stdout( $texts{temp}->fh() );
    $handles->options( 'stdout' )->{direct} = 1;

    $gnupg->clear_passphrase();

    my $pid = $gnupg->decrypt( handles => $handles );

    waitpid $pid, 0;

    return $CHILD_ERROR == 0;
};


TEST
{
    return compare( $texts{alt_plain}->fn(), $texts{temp}->fn() ) == 0;
};