Skip to content

Commit 1aabc9b

Browse files
committed
Changes for 0.5.1.
1 parent ca8e378 commit 1aabc9b

File tree

4 files changed

+59
-43
lines changed

4 files changed

+59
-43
lines changed

README.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,44 @@ Change log
6868
.. note:: GCnn refers to an issue nn on Google Code.
6969

7070

71-
0.5.1 (future)
71+
0.5.2 (future)
7272
--------------
7373

7474
Released: Not yet
7575

76-
* Added TRUST_EXPIRED to trust_keys. Thanks to Leif Liddy for the patch.
7776

78-
* Fix #206: Remove deprecated --always-trust in favour of --trust-model always
77+
0.5.1
78+
-----
79+
80+
Released: 2023-07-22
81+
82+
* Added ``TRUST_EXPIRED`` to ``trust_keys``. Thanks to Leif Liddy for the patch.
83+
84+
* Fix #206: Remove deprecated ``--always-trust`` in favour of ``--trust-model always``
7985

8086
* Fix #208: Add ``status_detail`` attribute to result objects which is populated when
8187
the status is ``'invalid recipient'`` (encryption/decryption) or ``'invalid signer'``
82-
(signing).
88+
(signing). This attribute will be set when the result object's ``status`` attribute is
89+
set to ``invalid recipient`` and will contain more information about the failure in the
90+
form of ``reason:ident`` where ``reason`` is a text description of the reason, and
91+
``ident`` identifies the recipient key.
8392

8493
* Add ``scan_keys_mem()`` function to scan keys in a string. Thanks to Sky Moore
8594
for the patch.
8695

8796
* Fix #214: Handle multiple signatures when one of them is invalid or unverified.
8897

98+
* A ``problems`` attribute was added which holds problems reported by ``gpg``
99+
during verification. This is a list of dictionaries, one for each reported
100+
problem. Each dictionary will have ``status`` and ``keyid`` keys indicating
101+
the problem and the corresponding key; other information in the dictionaries
102+
will be error specific.
103+
104+
* Fix #217: Use machine-readable interface to query the ``gpg`` version. Thanks to Justus
105+
Winter for the patch.
106+
107+
* Added the ability to export keys to a file. Thanks to Leif Liddy for the patch.
108+
89109

90110
0.5.0
91111
-----

docs/index.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,23 @@ verbose (defaults to ``False``)
165165
Print information (e.g. the gpg command lines, and status messages returned by
166166
gpg) to the console. You don't generally need to set this option, since the module
167167
uses Python's ``logging`` package to provide more flexible functionality. The
168-
status messages from GPG are quite voluminous, especially during key generation.
168+
status messages from ``gpg`` are quite voluminous, especially during key generation.
169169
use_agent (defaults to ``False``)
170-
If specified as True, the ``--use-agent`` parameter is passed to GPG, asking it to
170+
If specified as True, the ``--use-agent`` parameter is passed to ``gpg``, asking it to
171171
use any in-memory GPG agent (which remembers your credentials).
172172
keyring (defaults to ``None``)
173173
If specified, the value is used as the name of the keyring file. The default
174174
keyring is not used. A list of paths to keyring files can also be specified.
175175
options (defaults to ``None``)
176176
If specified, the value should be a list of additional command-line options to
177-
pass to GPG.
177+
pass to ``gpg``.
178178
secret_keyring (defaults to ``None``)
179179
If specified, the value is used as the name of the secret keyring file. A list of
180180
paths to secret keyring files can also be specified. *Note that these files are
181181
not used by GnuPG >= 2.1.*
182182
env (defaults to ``None``)
183183
If specified, the value is used as the environment variables used when calling the GPG
184+
executable.
184185

185186
.. versionchanged:: 0.3.4
186187
The ``keyring`` argument can now also be a list of keyring filenames.
@@ -198,6 +199,8 @@ env (defaults to ``None``)
198199
``locale.getpreferredencoding()`` or, failing that, ``sys.stdin.encoding``, and
199200
failing that, ``utf-8``.
200201

202+
.. versionadded:: 0.5.0
203+
The ``env`` argument was added.
201204

202205
If the ``gpgbinary`` executable cannot be found, a ``ValueError`` is raised in
203206
:meth:`GPG.__init__`.
@@ -468,6 +471,8 @@ The ``export_keys`` method has some additional keyword arguments:
468471
passphrase is to be passed to ``gpg`` via pinentry, you wouldn't pass it here - so
469472
specify ``expect_passphrase=False`` in that case. If you don't do that, and don't
470473
pass a passphrase, a ``ValueError`` will be raised.
474+
* ``output`` - defaults to ``None``, but if specified, should be the pathname of a file
475+
to which the exported keys should be written.
471476

472477
.. versionadded:: 0.3.7
473478
The ``armor`` and ``minimal`` keyword arguments were added.
@@ -478,6 +483,9 @@ The ``export_keys`` method has some additional keyword arguments:
478483
.. versionadded:: 0.4.2
479484
The ``expect_passphrase`` keyword argument was added.
480485

486+
.. versionadded:: 0.5.1
487+
The ``output`` keyword argument was added.
488+
481489
.. index:: Key; importing
482490

483491
.. index:: Key; receiving

gnupg.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
and so does not work on Windows). Renamed to gnupg.py to avoid confusion with
2828
the previous versions.
2929
30-
Modifications Copyright (C) 2008-2022 Vinay Sajip. All rights reserved.
30+
Modifications Copyright (C) 2008-2023 Vinay Sajip. All rights reserved.
3131
3232
For the full documentation, see https://docs.red-dove.com/python-gnupg/ or
3333
https://gnupg.readthedocs.io/
@@ -43,9 +43,9 @@
4343
import sys
4444
import threading
4545

46-
__version__ = '0.5.1.dev0'
46+
__version__ = '0.5.1'
4747
__author__ = 'Vinay Sajip'
48-
__date__ = '$23-Aug-2022 16:36:40$'
48+
__date__ = '$22-Jul-2023 16:36:40$'
4949

5050
STARTUPINFO = None
5151
if os.name == 'nt': # pragma: no cover
@@ -317,11 +317,7 @@ def update_sig_info(**kwargs):
317317
self.valid = False
318318
self.status = 'signature bad'
319319
self.key_id, self.username = value.split(None, 1)
320-
self.problems.append({
321-
'status': self.status,
322-
'keyid': self.key_id,
323-
'user': self.username
324-
})
320+
self.problems.append({'status': self.status, 'keyid': self.key_id, 'user': self.username})
325321
update_sig_info(keyid=self.key_id, username=self.username, status=self.status)
326322
elif key == 'ERRSIG': # pragma: no cover
327323
self.valid = False
@@ -346,11 +342,7 @@ def update_sig_info(**kwargs):
346342
self.status = 'signature expired'
347343
self.key_id, self.username = value.split(None, 1)
348344
update_sig_info(keyid=self.key_id, username=self.username, status=self.status)
349-
self.problems.append({
350-
'status': self.status,
351-
'keyid': self.key_id,
352-
'user': self.username
353-
})
345+
self.problems.append({'status': self.status, 'keyid': self.key_id, 'user': self.username})
354346
elif key == 'GOODSIG':
355347
self.valid = True
356348
self.status = 'signature good'
@@ -379,18 +371,12 @@ def update_sig_info(**kwargs):
379371
self.valid = False
380372
self.key_id = value
381373
self.status = 'no public key'
382-
self.problems.append({
383-
'status': self.status,
384-
'keyid': self.key_id
385-
})
374+
self.problems.append({'status': self.status, 'keyid': self.key_id})
386375
elif key == 'NO_SECKEY': # pragma: no cover
387376
self.valid = False
388377
self.key_id = value
389378
self.status = 'no secret key'
390-
self.problems.append({
391-
'status': self.status,
392-
'keyid': self.key_id
393-
})
379+
self.problems.append({'status': self.status, 'keyid': self.key_id})
394380
elif key in ('EXPKEYSIG', 'REVKEYSIG'): # pragma: no cover
395381
# signed with expired or revoked key
396382
self.valid = False
@@ -401,10 +387,7 @@ def update_sig_info(**kwargs):
401387
self.key_status = 'signing key was revoked'
402388
self.status = self.key_status
403389
update_sig_info(status=self.status, keyid=self.key_id)
404-
self.problems.append({
405-
'status': self.status,
406-
'keyid': self.key_id
407-
})
390+
self.problems.append({'status': self.status, 'keyid': self.key_id})
408391
elif key in ('UNEXPECTED', 'FAILURE'): # pragma: no cover
409392
self.valid = False
410393
if key == 'UNEXPECTED':
@@ -437,10 +420,9 @@ def update_sig_info(**kwargs):
437420
# See issue GH-191
438421
self.valid = False
439422
self.status = 'signature expected but not found'
440-
elif key in ('DECRYPTION_INFO', 'PLAINTEXT', 'PLAINTEXT_LENGTH',
441-
'BEGIN_SIGNING', 'KEY_CONSIDERED'):
423+
elif key in ('DECRYPTION_INFO', 'PLAINTEXT', 'PLAINTEXT_LENGTH', 'BEGIN_SIGNING', 'KEY_CONSIDERED'):
442424
pass
443-
elif key in ('NEWSIG',):
425+
elif key in ('NEWSIG', ):
444426
# Only sent in gpg2. Clear any signature ID, to be set by a following SIG_ID
445427
self.signature_id = None
446428
else: # pragma: no cover
@@ -1618,8 +1600,8 @@ def delete_keys(self, fingerprints, secret=False, passphrase=None, expect_passph
16181600
16191601
expect_passphrase (bool): Whether a passphrase is expected.
16201602
1621-
exclamation_mode (bool): If specified, a `'!'` is appended to each fingerprint. This deletes only a subkey or
1622-
an entire key, depending on what the fingerprint refers to.
1603+
exclamation_mode (bool): If specified, a `'!'` is appended to each fingerprint. This deletes only a subkey
1604+
or an entire key, depending on what the fingerprint refers to.
16231605
16241606
.. note:: Passphrases
16251607

test_gnupg.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
A test harness for gnupg.py.
44
5-
Copyright (C) 2008-2022 Vinay Sajip. All rights reserved.
5+
Copyright (C) 2008-2023 Vinay Sajip. All rights reserved.
66
"""
77
import argparse
88
import json
@@ -16,6 +16,11 @@
1616
import tempfile
1717
import unittest
1818

19+
try:
20+
unicode
21+
except NameError:
22+
unicode = str
23+
1924
try:
2025
from unittest import skipIf
2126
except ImportError: # pragma: no cover
@@ -30,7 +35,7 @@ def skipIf(condition, message):
3035
import gnupg
3136

3237
__author__ = 'Vinay Sajip'
33-
__date__ = '$23-Aug-2022 16:37:02$'
38+
__date__ = '$22-Jul-2023 16:37:02$'
3439

3540
ALL_TESTS = True
3641

@@ -726,7 +731,7 @@ def test_scan_keys(self):
726731
fd, key_fn = tempfile.mkstemp(prefix='pygpg-test-')
727732
os.write(fd, KEYS_TO_IMPORT.encode('ascii'))
728733
os.close(fd)
729-
test_files = (key_fn,)
734+
test_files = (key_fn, )
730735
try:
731736
for fn in test_files:
732737
logger.debug('scanning keys in %s', fn)
@@ -746,7 +751,7 @@ def test_scan_keys_mem(self):
746751
'Gary Gross (A test user) <[email protected]>',
747752
'Danny Davis (A test user) <[email protected]>',
748753
])
749-
for key in (KEYS_TO_IMPORT,):
754+
for key in (KEYS_TO_IMPORT, ):
750755
logger.debug('testing scan_keys')
751756
data = self.gpg.scan_keys_mem(key)
752757
self.assertEqual(0, data.returncode, 'Non-zero return code')
@@ -1560,8 +1565,9 @@ def test_multiple_signatures_one_invalid(self):
15601565
set([
15611566
'test_deletion', 'test_import_and_export', 'test_list_keys_after_generation', 'test_list_signatures',
15621567
'test_key_generation_with_invalid_key_type', 'test_key_generation_with_escapes', 'test_key_generation_input',
1563-
'test_key_generation_with_colons', 'test_search_keys', 'test_scan_keys', 'test_scan_keys_mem', 'test_key_trust', 'test_add_subkey',
1564-
'test_add_subkey_with_invalid_key_type', 'test_deletion_subkey', 'test_list_subkey_after_generation'
1568+
'test_key_generation_with_colons', 'test_search_keys', 'test_scan_keys', 'test_scan_keys_mem',
1569+
'test_key_trust', 'test_add_subkey', 'test_add_subkey_with_invalid_key_type', 'test_deletion_subkey',
1570+
'test_list_subkey_after_generation'
15651571
]),
15661572
'import':
15671573
set(['test_import_only', 'test_doctest_import_keys']),

0 commit comments

Comments
 (0)