Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/psi/zfaes.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2021 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, for further information.
14
*/
15
16
17
18
/* this is the ps interpreter interface to the AES cipher filter
19
   used in PDF encryption. We currently provide only decode support. */
20
21
#include "memory_.h"
22
#include "ghost.h"
23
#include "oper.h"
24
#include "gsstruct.h"
25
#include "ialloc.h"
26
#include "idict.h"
27
#include "idparam.h"
28
#include "stream.h"
29
#include "strimpl.h"
30
#include "ifilter.h"
31
#include "saes.h"
32
33
/* <source> <dict> aes/filter <file> */
34
35
static int
36
z_aes_d(i_ctx_t * i_ctx_p)
37
0
{
38
0
    os_ptr op = osp;   /* i_ctx_p->op_stack.stack.p defined in osstack.h */
39
0
    ref *sop = NULL;
40
0
    stream_aes_state state;
41
0
    int use_padding;
42
43
    /* extract the key from the parameter dictionary */
44
0
    check_type(*op, t_dictionary);
45
0
    check_dict_read(*op);
46
0
    if (dict_find_string(op, "Key", &sop) <= 0)
47
0
        return_error(gs_error_rangecheck);
48
0
    check_type(*sop, t_string);
49
0
    s_aes_set_key(&state, sop->value.const_bytes, r_size(sop));
50
51
    /* extract the padding flag, which defaults to true for compatibility */
52
0
    if (dict_bool_param(op, "Padding", 1, &use_padding) < 0)
53
0
        return_error(gs_error_rangecheck);
54
55
0
    s_aes_set_padding(&state, use_padding);
56
57
    /* we pass npop=0, since we've no arguments left to consume */
58
    /* FIXME: passing 0 instead of the usual rspace(sop) will allocate
59
       storage for filter state from the same memory pool as the stream
60
       it's coding. this caused no trouble when we were the arcfour cipher
61
       and maintained no pointers. */
62
0
    return filter_read(i_ctx_p, 0, &s_aes_template,
63
0
                       (stream_state *) & state, 0);
64
0
}
65
66
/* Match the above routine to its postscript filter name.
67
   This is how our static routines get called externally. */
68
const op_def zfaes_op_defs[] = {
69
    op_def_begin_filter(),
70
    {"2AESDecode", z_aes_d},
71
    op_def_end(0)
72
};