Use a single password_hash function

Using two different functions makes no sense in Python. A single
function with an optional argument is more Pythonistic.
This commit is contained in:
Rodolphe Breard 2017-12-17 13:07:07 +01:00
parent cd287242b0
commit 935b0acf26
2 changed files with 2 additions and 5 deletions

View file

@ -63,10 +63,7 @@ class LibreAuthPassError(Exception):
else:
self.message = 'unknown error'
def password_hash(password):
return password_hash_standard(password, NOSTANDARD)
def password_hash_standard(password, standard):
def password_hash(password, standard=NOSTANDARD):
pass_len = len(password)
if pass_len < PASSWORD_MIN_LEN:
raise LibreAuthPassError(1)

View file

@ -45,7 +45,7 @@ class PasswordTestCase(unittest.TestCase):
def test_std(self):
p = b'my super password'
for std in (NOSTANDARD, NIST80063B, ):
h = password_hash_standard(p, NIST80063B)
h = password_hash(p, standard=std)
self.assertTrue(h.startswith('$'))
self.assertEqual(len(h.split('$')), 5)
self.assertTrue(is_valid(p, h))