def _norm_algs(self, algs): """normalize algs parameter""" # determine default algs value if algs is None: # derive algs list from checksum (if present). chk = self.checksum if chk is not None: return sorted(chk) elif self.use_defaults: return list(self.default_algs) else: raise TypeError("no algs list specified") elif self.checksum is not None: raise RuntimeError("checksum & algs kwds are mutually exclusive") # parse args value if isinstance(algs, str): algs = splitcomma(algs) algs = sorted(norm_hash_name(alg, 'iana') for alg in algs) if any(len(alg)>9 for alg in algs): raise ValueError("SCRAM limits alg names to max of 9 characters") if 'sha-1' not in algs: # NOTE: required because of SCRAM spec (rfc 5802) raise ValueError("sha-1 must be in algorithm list of scram hash") return algs
def _norm_algs(self, algs): "normalize algs parameter" # determine default algs value if algs is None: # derive algs list from checksum (if present). chk = self.checksum if chk is not None: return sorted(chk) elif self.use_defaults: return list(self.default_algs) else: raise TypeError("no algs list specified") elif self.checksum is not None: raise RuntimeError("checksum & algs kwds are mutually exclusive") # parse args value if isinstance(algs, str): algs = splitcomma(algs) algs = sorted(norm_hash_name(alg, 'iana') for alg in algs) if any(len(alg)>9 for alg in algs): raise ValueError("SCRAM limits alg names to max of 9 characters") if 'sha-1' not in algs: # NOTE: required because of SCRAM spec (rfc 5802) raise ValueError("sha-1 must be in algorithm list of scram hash") return algs
def _norm_algs(cls, algs): """normalize algs parameter""" if isinstance(algs, native_string_types): algs = splitcomma(algs) algs = sorted(norm_hash_name(alg, 'iana') for alg in algs) if any(len(alg) > 9 for alg in algs): raise ValueError("SCRAM limits alg names to max of 9 characters") if 'sha-1' not in algs: # NOTE: required because of SCRAM spec (rfc 5802) raise ValueError("sha-1 must be in algorithm list of scram hash") return algs
def _norm_algs(cls, algs): """normalize algs parameter""" if isinstance(algs, native_string_types): algs = splitcomma(algs) algs = sorted(norm_hash_name(alg, 'iana') for alg in algs) if any(len(alg)>9 for alg in algs): raise ValueError("SCRAM limits alg names to max of 9 characters") if 'sha-1' not in algs: # NOTE: required because of SCRAM spec (rfc 5802) raise ValueError("sha-1 must be in algorithm list of scram hash") return algs
def test_splitcomma(self): from passlib.utils import splitcomma self.assertEqual(splitcomma(""), []) self.assertEqual(splitcomma(","), []) self.assertEqual(splitcomma("a"), ['a']) self.assertEqual(splitcomma(" a , "), ['a']) self.assertEqual(splitcomma(" a , b"), ['a', 'b']) self.assertEqual(splitcomma(" a, b, "), ['a', 'b'])
def _parse_policy_value(cat, name, opt, value): "helper to parse policy values" #FIXME: kinda primitive to parse things this way :| if name == "context": if opt in _context_comma_options: if isinstance(value, str): return splitcomma(value) elif opt == "min_verify_time": return float(value) return value else: #try to coerce everything to int try: return int(value) except ValueError: return value