[Pkg-gnupg-commit] [gpgme] 06/412: Updated encrypt-to-all
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Thu Sep 22 21:26:03 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gpgme.
commit 1c87ecb86ae364b18f69bca726021271fefaa1c1
Author: Ben McGinnes <ben at adversary.org>
Date: Sun May 17 04:03:49 2015 +1000
Updated encrypt-to-all
* Changed plaintext string to byte literal.
* Nested key selection in a try/except statement in case of
UnicodeEncodeError instances.
* Tested successfully on over 9,000 keys.
---
lang/py3-pyme/examples/encrypt-to-all.py | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/lang/py3-pyme/examples/encrypt-to-all.py b/lang/py3-pyme/examples/encrypt-to-all.py
index 087e6f7..8f9d250 100755
--- a/lang/py3-pyme/examples/encrypt-to-all.py
+++ b/lang/py3-pyme/examples/encrypt-to-all.py
@@ -18,9 +18,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-This program will try to encrypt a simple message to each key on your keyring.
-If your keyring has any invalid keys on it, those keys will be removed
-and it will re-try the encryption."""
+This program will try to encrypt a simple message to each key on your
+keyring. If your keyring has any invalid keys on it, those keys will
+be skipped and it will re-try the encryption."""
from pyme import core
from pyme.core import Data, Context
@@ -28,7 +28,7 @@ from pyme.constants import validity
core.check_version(None)
-plain = Data('This is my message.')
+plain = Data(b'This is my message.')
c = Context()
c.set_armor(1)
@@ -41,16 +41,19 @@ def sendto(keylist):
names = []
for key in c.op_keylist_all(None, 0):
- print(" *** Found key for %s" % key.uids[0].uid)
- valid = 0
- for subkey in key.subkeys:
- keyid = subkey.keyid
- if keyid == None:
- break
- can_encrypt = subkey.can_encrypt
- valid += can_encrypt
- print(" Subkey %s: encryption %s" % \
- (keyid, can_encrypt and "enabled" or "disabled"))
+ try:
+ print(" *** Found key for %s" % key.uids[0].uid)
+ valid = 0
+ for subkey in key.subkeys:
+ keyid = subkey.keyid
+ if keyid == None:
+ break
+ can_encrypt = subkey.can_encrypt
+ valid += can_encrypt
+ print(" Subkey %s: encryption %s" % \
+ (keyid, can_encrypt and "enabled" or "disabled"))
+ except UnicodeEncodeError as e:
+ print(e)
if valid:
names.append(key)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git
More information about the Pkg-gnupg-commit
mailing list