2016-06-06 12:08:59 +00:00
|
|
|
# Copyright (C) 2016 g10 Code GmbH
|
|
|
|
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
|
|
|
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2016-10-28 20:45:49 +00:00
|
|
|
"""gpg: GnuPG Interface for Python (GPGME bindings)
|
2015-05-05 17:09:44 +00:00
|
|
|
|
2016-10-28 20:45:49 +00:00
|
|
|
Welcome to gpg, the GnuPG Interface for Python.
|
2015-05-05 17:09:44 +00:00
|
|
|
|
|
|
|
The latest release of this package may be obtained from
|
2016-06-06 12:08:59 +00:00
|
|
|
https://www.gnupg.org
|
|
|
|
|
2015-05-05 17:09:44 +00:00
|
|
|
FEATURES
|
|
|
|
--------
|
|
|
|
|
|
|
|
* Feature-rich, full implementation of the GPGME library. Supports
|
2016-06-06 12:08:59 +00:00
|
|
|
all GPGME features. Callback functions may be written in pure
|
|
|
|
Python. Exceptions raised in callbacks are properly propagated.
|
2015-05-05 17:09:44 +00:00
|
|
|
|
|
|
|
* Ability to sign, encrypt, decrypt, and verify data.
|
|
|
|
|
|
|
|
* Ability to list keys, export and import keys, and manage the keyring.
|
|
|
|
|
|
|
|
* Fully object-oriented with convenient classes and modules.
|
|
|
|
|
2016-06-08 16:58:57 +00:00
|
|
|
QUICK EXAMPLE
|
|
|
|
-------------
|
|
|
|
|
2016-10-28 20:45:49 +00:00
|
|
|
>>> import gpg
|
|
|
|
>>> with gpg.Context() as c:
|
|
|
|
>>> with gpg.Context() as c:
|
2016-06-08 16:58:57 +00:00
|
|
|
... cipher, _, _ = c.encrypt("Hello world :)".encode(),
|
|
|
|
... passphrase="abc")
|
|
|
|
... c.decrypt(cipher, passphrase="abc")
|
|
|
|
...
|
|
|
|
(b'Hello world :)',
|
2016-10-28 20:45:49 +00:00
|
|
|
<gpg.results.DecryptResult object at 0x7f5ab8121080>,
|
|
|
|
<gpg.results.VerifyResult object at 0x7f5ab81219b0>)
|
2016-06-08 16:58:57 +00:00
|
|
|
|
2015-05-05 17:09:44 +00:00
|
|
|
GENERAL OVERVIEW
|
|
|
|
----------------
|
|
|
|
|
|
|
|
For those of you familiar with GPGME, you will be right at home here.
|
|
|
|
|
2016-10-28 20:45:49 +00:00
|
|
|
The python gpg module is, for the most part, a direct interface to the C GPGME
|
2015-05-05 17:09:44 +00:00
|
|
|
library. However, it is re-packaged in a more Pythonic way --
|
|
|
|
object-oriented with classes and modules. Take a look at the classes
|
|
|
|
defined here -- they correspond directly to certain object types in GPGME
|
|
|
|
for C. For instance, the following C code:
|
|
|
|
|
|
|
|
gpgme_ctx_t context;
|
|
|
|
gpgme_new(&context);
|
|
|
|
...
|
|
|
|
gpgme_op_encrypt(context, recp, 1, plain, cipher);
|
|
|
|
|
|
|
|
Translates into the following Python code:
|
|
|
|
|
|
|
|
context = core.Context()
|
|
|
|
...
|
|
|
|
context.op_encrypt(recp, 1, plain, cipher)
|
|
|
|
|
|
|
|
The Python module automatically does error-checking and raises Python
|
2016-10-28 20:45:49 +00:00
|
|
|
exception gpg.errors.GPGMEError when GPGME signals an error. getcode()
|
2015-05-05 17:09:44 +00:00
|
|
|
and getsource() of this exception return code and source of the error.
|
|
|
|
|
|
|
|
IMPORTANT NOTE
|
|
|
|
--------------
|
|
|
|
This documentation only covers a small subset of available GPGME functions and
|
|
|
|
methods. Please consult the documentation for the C library
|
|
|
|
for comprehensive coverage.
|
|
|
|
|
|
|
|
This library uses Python's reflection to automatically detect the methods
|
|
|
|
that are available for each class, and as such, most of those methods
|
|
|
|
do not appear explicitly anywhere. You can use dir() python built-in command
|
|
|
|
on an object to see what methods and fields it has but their meaning can
|
|
|
|
be found only in GPGME documentation.
|
|
|
|
|
|
|
|
FOR MORE INFORMATION
|
|
|
|
--------------------
|
2016-10-28 20:45:49 +00:00
|
|
|
GnuPG homepage: https://www.gnupg.org/
|
2016-06-08 16:58:57 +00:00
|
|
|
GPGME documentation: https://www.gnupg.org/documentation/manuals/gpgme/
|
2015-05-05 17:09:44 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-09-14 09:39:00 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
del absolute_import, print_function, unicode_literals
|
|
|
|
|
2016-07-28 14:29:05 +00:00
|
|
|
from . import core
|
|
|
|
from . import errors
|
|
|
|
from . import constants
|
|
|
|
from . import util
|
|
|
|
from . import callbacks
|
|
|
|
from . import version
|
2016-06-08 16:58:57 +00:00
|
|
|
from .core import Context
|
|
|
|
from .core import Data
|
2016-07-28 14:29:05 +00:00
|
|
|
|
|
|
|
# Interface hygiene.
|
|
|
|
|
|
|
|
# Drop the low-level gpgme that creeps in for some reason.
|
|
|
|
gpgme = None
|
|
|
|
del gpgme
|
|
|
|
|
|
|
|
# This is a white-list of symbols. Any other will alert pyflakes.
|
|
|
|
_ = [Context, Data, core, errors, constants, util, callbacks, version]
|
|
|
|
del _
|
|
|
|
|
2018-08-10 01:25:01 +00:00
|
|
|
__all__ = [
|
|
|
|
"Context", "Data", "core", "errors", "constants", "util", "callbacks",
|
|
|
|
"version"
|
|
|
|
]
|