

def choose_mechanism(self, mechanism_choices, allow_anonymous=True, allow_plaintext=True, allow_active=True, allow_dictionary=True):
    '\n        Choose a mechanism from a list of mechanisms based on security\n        scores for mechanisms and required properties of the mechanism.\n\n        If `allow_anonymous` is ``False``, mechanisms that allow anonymous\n        authentication will not be considered.\n\n        If `allow_plaintext` is ``False``, mechanisms that transmit\n        sensitive information in plaintext (and are thus susceptible to\n        passive listening attacks) will not be considered.\n\n        If `allow_active` is ``False``, mechanisms that are susceptible\n        to active non-dictionary attacks (MITM, injection) will not be\n        considered.\n\n        If `allow_dictionary` is ``False, mechanisms that are susceptible\n        to passive dictionary attacks will not be considered.\n        '
    candidates = [mech_mod.mechanisms[m] for choice in mechanism_choices if (choice in mech_mod.mechanisms)]
    if (not allow_anonymous):
        candidates = [m for m in candidates if (not m.allows_anonymous)]
    if (not allow_plaintext):
        candidates = [m for m in candidates if (not m.uses_plaintext)]
    if (not allow_active):
        candidates = [m for m in candidates if m.active_safe]
    if (not allow_dictionary):
        candidates = [m for m in candidates if m.dictionary_safe]
    if (not candidates):
        raise SASLError('None of the mechanisms listed meet all required properties')
    mech_class = max(candidates, key=(lambda mech: mech.score))
    self.mechanism = mech_class.name
    self._chosen_mech = mech_class(self, **self._mech_props)

dataset/ETHPy150Open thobbs/pure-sasl/puresasl/client.py SASLClient.choose_mechanism/VarMisuse@37/320 `choice`->`m`