aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2015-05-16 18:03:49 +0000
committerBen McGinnes <[email protected]>2015-05-16 18:03:49 +0000
commit1c87ecb86ae364b18f69bca726021271fefaa1c1 (patch)
treeeb42ad45d87a0374437cba415c7f6cc895938749
parentPassphrase update (diff)
downloadgpgme-1c87ecb86ae364b18f69bca726021271fefaa1c1.tar.gz
gpgme-1c87ecb86ae364b18f69bca726021271fefaa1c1.zip
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.
-rwxr-xr-xlang/py3-pyme/examples/encrypt-to-all.py31
1 files 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 087e6f72..8f9d2500 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)