python: hkp key importer

* Tweaked it slightly to avoid repetition of key searches when there
  is only one search pattern to check (i.e. usually a single key ID or
  fingerprint).
This commit is contained in:
Ben McGinnes 2018-12-11 09:55:15 +11:00
parent 2e7a14c9b3
commit 772b5aae24

View File

@ -58,32 +58,37 @@ if pattern is not None:
if keyed is True: if keyed is True:
try: try:
fob = server.search(pattern) fob = server.search(pattern)
except: except Exception as e:
fob = None fob = None
if fob is not None: if fob is not None:
keys.append(fob[0]) keys.append(fob[0])
else:
pass
else: else:
pass pass
else:
pass
for logrus in pattern.split(): for logrus in pattern.split():
try: if logrus != pattern:
key = server.search(hex(int(logrus, 16))) try:
hexed = True key = server.search(hex(int(logrus, 16)))
except ValueError as ve: hexed = True
key = server.search(logrus) except ValueError as ve:
hexed = False key = server.search(logrus)
hexed = False
if key is not None: if key is not None:
keys.append(key[0]) keys.append(key[0])
if hexed is True: if hexed is True:
try: try:
fob = server.search(logrus) fob = server.search(logrus)
except: except Exception as e:
fob = None fob = None
if fob is not None: if fob is not None:
keys.append(fob[0]) keys.append(fob[0])
else:
pass
else:
pass
else: else:
pass pass
else: else: