From 488a4f389606423451dc36af3920803b2a14de7c Mon Sep 17 00:00:00 2001 From: Brian Dolbec Date: Sat, 22 Jun 2013 14:01:48 -0700 Subject: [PATCH] Add keyid/longkeyid separation and assignment --- gkeyldap/cli.py | 37 +++++++++++++++++++++++++++++-------- gkeyldap/search.py | 2 +- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/gkeyldap/cli.py b/gkeyldap/cli.py index b506f64..dae772a 100644 --- a/gkeyldap/cli.py +++ b/gkeyldap/cli.py @@ -20,6 +20,32 @@ from gkeyldap.search import (LdapSearch, UID, gkey2ldap_map, gkey2SEARCH) logger.setLevel(0) +# set some defaults +KEY_LEN = { + 'keyid': 8, + 'longkeyid': 16, +} + + +def get_key_ids(key, info): + '''Small utility function to return only keyid (short) + or longkeyid's + + @param key: string, the key lenght desired + @param info: list of keysid's to process + @return list of the desired key lengh id's + ''' + result = [] + for x in info: + if x.startswith('0x'): + mylen = KEY_LEN[key] + 2 + else: + mylen = KEY_LEN[key] + if len(x) == mylen: + result.append(x) + return result + + class Main(object): '''Main command line interface class''' @@ -188,7 +214,6 @@ class Main(object): return (x, target, search_field) - @staticmethod def build_gkeydict(info): keyinfo = {} @@ -222,6 +247,9 @@ class Main(object): values = info[field] if values and field in ['uid', 'cn' ]: value = values[0] + # separate out short/long key id's + elif values and x in ['keyid', 'longkeyid']: + value = get_key_ids(x, values) else: value = values if 'undefined' in values: @@ -234,10 +262,3 @@ class Main(object): keyinfo.append(None) return keyinfo - -if __name__ == '__main__': - - Main() - - - diff --git a/gkeyldap/search.py b/gkeyldap/search.py index 66721f1..8d323f4 100644 --- a/gkeyldap/search.py +++ b/gkeyldap/search.py @@ -19,7 +19,7 @@ gkey2ldap_map = { 'nick': 'uid', 'name': 'cn', 'keyid': 'gpgkey', - 'longkeyid': '', + 'longkeyid': 'gpgkey', 'keyring': '', 'fingerprint': 'gpgfingerprint' } -- 2.26.2