|
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 sys
|
|
Packit Service |
672cf4 |
import random
|
|
Packit Service |
672cf4 |
import gpg
|
|
Packit Service |
672cf4 |
import support
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if len(sys.argv) == 2:
|
|
Packit Service |
672cf4 |
nbytes = int(sys.argv[1])
|
|
Packit Service |
672cf4 |
else:
|
|
Packit Service |
672cf4 |
nbytes = 100000
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
c = gpg.Context()
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
ntoread = nbytes
|
|
Packit Service |
672cf4 |
def read_cb(amount):
|
|
Packit Service |
672cf4 |
global ntoread
|
|
Packit Service |
672cf4 |
chunk = ntoread if ntoread < amount else amount
|
|
Packit Service |
672cf4 |
ntoread -= chunk
|
|
Packit Service |
672cf4 |
assert ntoread >= 0
|
|
Packit Service |
672cf4 |
assert chunk >= 0
|
|
Packit Service |
672cf4 |
return bytes(bytearray(random.randrange(256) for i in range(chunk)))
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
nwritten = 0
|
|
Packit Service |
672cf4 |
def write_cb(data):
|
|
Packit Service |
672cf4 |
global nwritten
|
|
Packit Service |
672cf4 |
nwritten += len(data)
|
|
Packit Service |
672cf4 |
return len(data)
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
source = gpg.Data(cbs=(read_cb, None, None, lambda: None))
|
|
Packit Service |
672cf4 |
sink = gpg.Data(cbs=(None, write_cb, None, lambda: None))
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
keys = []
|
|
Packit Service |
672cf4 |
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
|
Packit Service |
672cf4 |
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
c.op_encrypt(keys, gpg.constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
|
Packit Service |
672cf4 |
result = c.op_encrypt_result()
|
|
Packit Service |
672cf4 |
assert not result.invalid_recipients, \
|
|
Packit Service |
672cf4 |
"Invalid recipient encountered: {}".format(result.invalid_recipients.fpr)
|
|
Packit Service |
672cf4 |
assert ntoread == 0
|
|
Packit Service |
672cf4 |
|
|
Packit Service |
672cf4 |
if support.verbose:
|
|
Packit Service |
6c01f9 |
sys.stderr.write(
|
|
Packit Service |
6c01f9 |
"plaintext={} bytes, ciphertext={} bytes\n".format(nbytes, nwritten))
|