1#!/usr/bin/env python
2
3# Copyright (C) 2016 g10 Code GmbH
4#
5# This file is part of GPGME.
6#
7# GPGME is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# GPGME is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
15# Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public
18# License along with this program; if not, see <https://www.gnu.org/licenses/>.
19
20from __future__ import absolute_import, print_function, unicode_literals
21
22import gpg
23import support
24
25del absolute_import, print_function, unicode_literals
26
27c = gpg.Context()
28
29source = gpg.Data(file=support.make_filename("cipher-1.asc"))
30sink = gpg.Data()
31
32c.op_decrypt(source, sink)
33result = c.op_decrypt_result()
34assert not result.unsupported_algorithm, \
35    "Unsupported algorithm: {}".format(result.unsupported_algorithm)
36
37support.print_data(sink)
38
39# Idiomatic interface.
40with gpg.Context() as c:
41    plaintext, _, _ = c.decrypt(open(support.make_filename("cipher-1.asc")), verify=False)
42    assert len(plaintext) > 0
43    assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
44        'Plaintext not found'
45
46    plaintext, _, _ = c.decrypt(open(support.make_filename("cipher-3.asc")), verify=False)
47    assert len(plaintext) > 0
48    assert plaintext.find(b'Reenact Studied Thermos Bonehead Unclasp Opposing') >= 0, \
49        'second Plaintext not found'
50
51    plaintext, _, _ = c.decrypt(open(support.make_filename("cipher-no-sig.asc")), verify=False)
52    assert len(plaintext) > 0
53    assert plaintext.find(b'Viscosity Dispersal Thimble Saturday Flaxseed Deflected') >= 0, \
54        'third Plaintext was not found'
55