From c2ce0f379d7740dac246d5378bb5746abea8be1f Mon Sep 17 00:00:00 2001 From: Pavlos Ratis Date: Sun, 25 May 2014 17:46:15 +0300 Subject: [PATCH] remove KEYLEN_MAP --- gkeyldap/actions.py | 10 +++++----- gkeyldap/search.py | 3 --- gkeys/config.py | 15 +-------------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/gkeyldap/actions.py b/gkeyldap/actions.py index 712f090..7c0608b 100644 --- a/gkeyldap/actions.py +++ b/gkeyldap/actions.py @@ -14,7 +14,7 @@ import os import re from collections import defaultdict -from gkeys.config import GKEY, KEYLEN_MAP +from gkeys.config import GKEY from gkeys.seed import Seeds from gkeyldap.search import (LdapSearch, UID, gkey2ldap_map, gkey2SEARCH) @@ -32,9 +32,9 @@ def get_key_ids(key_len, keyids): ''' result = [] for keyid in keyids: - target_len = KEYLEN_MAP[key_len] + target_len = 16 if keyid.startswith('0x'): - target_len = KEYLEN_MAP[key_len] + 2 + target_len = target_len + 2 if len(keyid) == target_len: result.append(keyid) return result @@ -155,7 +155,7 @@ class Actions(object): # assume it's good until an error is found is_good = True #self.logger.debug("Actions: build_gkeylist; info = %s" % str(info)) - for attr in GKEY._fields: + for attr in gkey2ldap_map: field = gkey2ldap_map[attr] if not field: keyinfo[attr] = None @@ -199,7 +199,7 @@ class Actions(object): values = [v.replace(' ', '') for v in values] # assign it to gpgkey to prevent a possible # "gpgkey" undefined error - gpgkey = ['0x' + x[-KEYLEN_MAP['longkeyid']:] for x in values] + gpgkey = ['0x' + x[-16:] for x in values] keyinfo['longkeyid'] = gpgkey self.logger.debug(' Generate gpgkey, NEW keyinfo[\'fingerprint\'] = %s' % str(keyinfo['longkeyid'])) diff --git a/gkeyldap/search.py b/gkeyldap/search.py index 087bee6..5f2ffbd 100644 --- a/gkeyldap/search.py +++ b/gkeyldap/search.py @@ -36,9 +36,6 @@ gkey2ldap_map = { 'keydir': 'uid', 'fingerprint': 'gpgfingerprint' } -# Sanity check they are in sync -if not sorted(gkey2ldap_map) == sorted(GKEY._fields): - raise "Search.py out of sync with GKEY class" # Now for some search field defaults diff --git a/gkeys/config.py b/gkeys/config.py index b1a0447..b932fb2 100644 --- a/gkeys/config.py +++ b/gkeys/config.py @@ -110,23 +110,10 @@ class GKeysConfig(GPGConfig): return super(GKeysConfig, self)._get_(key, subkey) -# set some defaults -KEYLEN_MAP = { - 'keyid': 8, - 'longkeyid': 16, -} - -class GKEY(namedtuple('GKEY', ['nick', 'name', 'keyid', 'longkeyid', - 'keydir', 'fingerprint'])): +class GKEY(namedtuple('GKEY', ['nick', 'name', 'keydir', 'fingerprint'])): '''Class to hold the relavent info about a key''' - # subclass __new__ to make both gkeys and gkeyldap work properly - # delete it when keyid and longkeyid are removed from LDAP - def __new__(cls, nick=None, name=None, keydir=None, fingerprint=None, - keyid=None, longkeyid=None): - return super(GKEY, cls).__new__(cls, nick, name, keydir, fingerprint, - keyid, longkeyid) field_types = {'nick': str, 'name': str, 'keyid': list, 'longkeyid': list, 'keydir': str, 'fingerprint': list} -- 2.26.2