def _clean_salt(self, salt): if not salt: return None elif issubclass(self.crypt_algo, HasRawSalt): ret = to_bytes(salt, encoding='ascii', errors='strict') else: ret = to_text(salt, encoding='ascii', errors='strict') # Ensure the salt has the correct padding if self.algorithm == 'bcrypt': ret = bcrypt64.repair_unused(ret) return ret
def _generate_salt(cls): # generate random salt as normal, # but repair last char so the padding bits always decode to zero. salt = super(_BcryptCommon, cls)._generate_salt() return bcrypt64.repair_unused(salt)