diff options
author | Ben McGinnes <[email protected]> | 2018-12-10 20:14:28 +0000 |
---|---|---|
committer | Ben McGinnes <[email protected]> | 2018-12-10 20:14:28 +0000 |
commit | 2e7a14c9b369096775a035091c197f2d438142a0 (patch) | |
tree | 651aaef023f839f92597fac266cd9bdd4415c8ab /lang/python/examples/howto/import-keys-hkp.py | |
parent | python: key import via HKP example (diff) | |
download | gpgme-2e7a14c9b369096775a035091c197f2d438142a0.tar.gz gpgme-2e7a14c9b369096775a035091c197f2d438142a0.zip |
python: HKP search and import updates
* Tweaked the code again so that it can also handle the cases where
someone has included a hexadecimal string in their user ID.
* Updated the HOWTO to match.
* Exported to .rst and .texi.
Diffstat (limited to 'lang/python/examples/howto/import-keys-hkp.py')
-rwxr-xr-x | lang/python/examples/howto/import-keys-hkp.py | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/lang/python/examples/howto/import-keys-hkp.py b/lang/python/examples/howto/import-keys-hkp.py index 832a888a..1abd0fd3 100755 --- a/lang/python/examples/howto/import-keys-hkp.py +++ b/lang/python/examples/howto/import-keys-hkp.py @@ -44,18 +44,51 @@ elif len(sys.argv) == 2: else: pattern = input("Enter the pattern to search for keys or user IDs: ") + if pattern is not None: try: key = server.search(hex(int(pattern, 16))) - except ValueError as e: + keyed = True + except ValueError as ve: key = server.search(pattern) - keys.append(key[0]) + keyed = False + + if key is not None: + keys.append(key[0]) + if keyed is True: + try: + fob = server.search(pattern) + except: + fob = None + if fob is not None: + keys.append(fob[0]) + else: + pass + else: + pass + for logrus in pattern.split(): try: key = server.search(hex(int(logrus, 16))) - except ValueErrer as ve: + hexed = True + except ValueError as ve: key = server.search(logrus) - keys.append(key[0]) + hexed = False + + if key is not None: + keys.append(key[0]) + if hexed is True: + try: + fob = server.search(logrus) + except: + fob = None + if fob is not None: + keys.append(fob[0]) + else: + pass + else: + pass + if len(keys) > 0: for key in keys: @@ -90,4 +123,4 @@ The key IDs for all considered keys were: print(result.imports[i].fpr) print("") else: - pass + print("No keys were imported or found.") |