예제 #1
0
 def testA01unique_order(self):
     """misc: unique_order() forward"""
     # simple
     l = [1, 1, 2, 2, 3, 3, 4, 4]
     new_l = unique_order(l)
     self.assertEqual(new_l, [1, 2, 3, 4])
     # a little harder
     l = [1, 2, 1, 2, 2, 3, 1, 3, 4, 3, 4, 2, 4]
     new_l = unique_order(l)
     self.assertEqual(new_l, [1, 2, 3, 4])
예제 #2
0
 def testA02unique_order(self):
     """misc: unique_order() reverse"""
     # a little harder still
     l = [1, 2, 1, 2, 2, 3, 1, 3, 4, 3, 4, 2, 4]
     new_l = unique_order(l, True)
     self.assertEqual(new_l, [1, 3, 2, 4])
예제 #3
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