Esempio n. 1
0
 def testA05intersect_order(self):
     """misc: intersect_order()"""
     a = [1, 2, 3, 4, 5, 10]
     b = [1, 3, 4, 5, 6, 10]
     c = [1, 3, 4, 5, 4, 5, 5, 10, None]
     ll = [a, b, c]
     tl = intersect_order(ll)
     self.assertEqual(tl, [1, 3, 4, 5, 10])
Esempio n. 2
0
def find_key_prefs(keys):
    """Return a dictionary with an intersection of keys' preferences.
    
    :Parameters:
        - `keys`: list of `openpgp.sap.msg.KeyMsg.KeyMsg` subclass instances

    :Returns: dictionary with keys 'sym', 'hash', 'comp' set with list of
        appropriate codes in descending order of popularity
    """
    sym_v, hash_v, comp_v = [], [], []

    for key in keys:
        sym_b = hash_b = comp_b = None # for *_v extension capability below
        sigs = [] # where to look for preference blocks

        for block in key._b_userids.list() + key._b_userattrs:
            sigs.extend([s for s in block.local_bindings + block.local_direct])

        # grab hashed local signatures
        has_hashed = lambda x: hasattr(x, 'hashed_subpkts')

        for sig in [s for s in sigs if has_hashed(s.body)]:

            # sigs are all "equal," so just fill up the spaces asap
            if CRYPT.verify(sig, block.leader, key._b_primary.leader):

                for subpkt in sig.body.hashed_subpkts:

                    if SIGSUB_SYMCODE == subpkt.type:
                        sym_b = subpkt.value
                    elif SIGSUB_HASHCODE == subpkt.type:
                        hash_b = subpkt.value
                    elif SIGSUB_COMPCODE == subpkt.type:
                        comp_b = subpkt.value

                    if sym_b and hash_b and comp_b: # break out
                        break

            if sym_b and hash_b and comp_b: # still breaking out..
                break

        # extend with list of preferences if present, otherwise nullify
        if sym_b and sym_v is not None:
            sym_v.append(unique_order(sym_b))
        else:
            sym_v = None

        if hash_b and hash_v is not None:
            hash_v.append(unique_order(hash_b))
        else:
            hash_v = None

        if comp_b and comp_v is not None:
            comp_v.append(unique_order(comp_b))
        else:
            comp_v = None

    tally = {'sym':[], 'hash':[], 'comp':[]}

    if sym_v:
        tally['sym'] += intersect_order(sym_v)

    if hash_v:
        tally['hash'] += intersect_order(hash_v)

    if comp_v:
        tally['comp'] += intersect_order(comp_v)

    return tally