Blame lang/python/tests/t-decrypt.py

Packit Service 672cf4
#!/usr/bin/env python
Packit Service 672cf4
Packit Service 672cf4
# Copyright (C) 2016 g10 Code GmbH
Packit Service 672cf4
#
Packit Service 672cf4
# This file is part of GPGME.
Packit Service 672cf4
#
Packit Service 672cf4
# GPGME is free software; you can redistribute it and/or modify it
Packit Service 672cf4
# under the terms of the GNU General Public License as published by
Packit Service 672cf4
# the Free Software Foundation; either version 2 of the License, or
Packit Service 672cf4
# (at your option) any later version.
Packit Service 672cf4
#
Packit Service 672cf4
# GPGME is distributed in the hope that it will be useful, but WITHOUT
Packit Service 672cf4
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit Service 672cf4
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
Packit Service 672cf4
# Public License for more details.
Packit Service 672cf4
#
Packit Service 672cf4
# You should have received a copy of the GNU Lesser General Public
Packit Service 6c01f9
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit Service 672cf4
Packit Service 672cf4
from __future__ import absolute_import, print_function, unicode_literals
Packit Service 6c01f9
del absolute_import, print_function, unicode_literals
Packit Service 672cf4
Packit Service 672cf4
import gpg
Packit Service 672cf4
import support
Packit Service 672cf4
Packit Service 672cf4
c = gpg.Context()
Packit Service 672cf4
Packit Service 672cf4
source = gpg.Data(file=support.make_filename("cipher-1.asc"))
Packit Service 672cf4
sink = gpg.Data()
Packit Service 672cf4
Packit Service 672cf4
c.op_decrypt(source, sink)
Packit Service 672cf4
result = c.op_decrypt_result()
Packit Service 672cf4
assert not result.unsupported_algorithm, \
Packit Service 672cf4
    "Unsupported algorithm: {}".format(result.unsupported_algorithm)
Packit Service 672cf4
Packit Service 672cf4
support.print_data(sink)
Packit Service 672cf4
Packit Service 672cf4
# Idiomatic interface.
Packit Service 672cf4
with gpg.Context() as c:
Packit Service 6c01f9
    plaintext, _, _ = c.decrypt(open(support.make_filename("cipher-1.asc")))
Packit Service 672cf4
    assert len(plaintext) > 0
Packit Service 672cf4
    assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
Packit Service 672cf4
        'Plaintext not found'