summaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2016-06-15 17:43:31 -0400
committerEli Collins <elic@assurancetechnologies.com>2016-06-15 17:43:31 -0400
commit713c0bb81f3cec4ee15715657c627a9757a2edf2 (patch)
tree51161d33d6fb5ff95fdd643ec1a50465a0e16ae9 /admin
parentd5ffe3e5645efa1737d659a564c54b45fff829d5 (diff)
downloadpasslib-713c0bb81f3cec4ee15715657c627a9757a2edf2.tar.gz
PasswordHash.hash() api shift: deprecating passing settings kwds into hash() --
callers should use handler.replace(**settings).hash() instead. this is being done because it greatly streamlines the internals of the .hash() implementation, and allows some redundant configuration parsing to be extracted from the .hash() methods and merged in with existing code in .replace(). this also opens things up for alternate code architectures for implementing new hashers, making it easier to wrap existing libraries (e.g. argon2). internals --------- * replaced a bunch of internal .hash(**settings) calls * GenericHandler - stripped out 'relaxed' keyword from constructor, since it's no longer passed by hash() etc. - _norm_checksum() now only invoked if checksum is specified (simplifies logic). keeping support for 'relaxed' mode, but only as explicit keyword. - removed some unused comments about .from_string() & .to_string() * HasSalt mixin: - .replace() now supports 'salt' keyword, creates variant which has a fixed salt string. - 'salt size' keyword removed from ctor, now handled by .replace() call - _norm_salt() converted to class method so it can be used by .replace() 'salt' keyword code. - per-instance bits of _norm_salt() relocated to HasSalt.__init__ proper - _generate_salt() converted to class method, since no longer depends on instance config. * HasRounds mixin: - similar to HasSalt, relocates per-instance bits of _norm_rounds() into HasRounds.__init__() proper. - remainder of _norm_rounds() turned into class method, merged with ._clip_to_valid_rounds() helper to reduce duplication. - _generate_rounds() converted to class method, since no longer depends on instance config. hashers ------- * fshp: added support for 'variant' keyword to replace() * unix_disabled: added support for 'marker' keyword to replace(), added UTs. * cisco_type7: to match HasSalt, added support for 'salt' keyword to replace(), added UTs. * sha256/512_crypt: now uses custom salt & rounds parsing, rather than relaxed kwd, to handle correctable-but-invalid config strings. unittests --------- * removed checks for PasslibConfigWarning when setting hash(rounds=) out of policy bounds, since that now *is* setting the policy. * adapted some handler ctor to deal w/ lack of 'relaxed' kwd docs ---- * updated docstrings listing hash() keywords for each scheme to list them as .replace() keywords. * updated example code to use .replace() * fleshed out api docs about the change
Diffstat (limited to 'admin')
-rw-r--r--admin/benchmarks.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/admin/benchmarks.py b/admin/benchmarks.py
index c6519e7..c7ce7b1 100644
--- a/admin/benchmarks.py
+++ b/admin/benchmarks.py
@@ -180,11 +180,12 @@ def test_context_calls():
schemes=[BlankHandler, AnotherHandler],
default="another",
blank__min_rounds=1500,
+ blank__default_rounds=2001,
blank__max_rounds=2500,
another__vary_rounds=100,
)
def helper():
- hash = ctx.hash(SECRET, rounds=2001)
+ hash = ctx.hash(SECRET)
ctx.verify(SECRET, hash)
ctx.verify_and_update(SECRET, hash)
ctx.verify_and_update(OTHER, hash)
@@ -200,11 +201,11 @@ def test_bcrypt_builtin():
import os
os.environ['PASSLIB_BUILTIN_BCRYPT'] = 'enabled'
bcrypt.set_backend("builtin")
- bcrypt.default_rounds = 10
+ handler = bcrypt.replace(rounds = 10)
def helper():
- hash = bcrypt.hash(SECRET)
- bcrypt.verify(SECRET, hash)
- bcrypt.verify(OTHER, hash)
+ hash = handler.hash(SECRET)
+ handler.verify(SECRET, hash)
+ handler.verify(OTHER, hash)
return helper
@benchmark.constructor()
@@ -212,11 +213,11 @@ def test_bcrypt_ffi():
"test bcrypt 'bcrypt' backend"
from passlib.hash import bcrypt
bcrypt.set_backend("bcrypt")
- bcrypt.default_rounds = 8
+ handler = bcrypt.replace(rounds=8)
def helper():
- hash = bcrypt.hash(SECRET)
- bcrypt.verify(SECRET, hash)
- bcrypt.verify(OTHER, hash)
+ hash = handler.hash(SECRET)
+ handler.verify(SECRET, hash)
+ handler.verify(OTHER, hash)
return helper
@benchmark.constructor()
@@ -235,7 +236,7 @@ def test_ldap_salted_md5():
"""test ldap_salted_md5"""
from passlib.hash import ldap_salted_md5 as handler
def helper():
- hash = handler.hash(SECRET, salt='....')
+ hash = handler.hash(SECRET)
handler.verify(SECRET, hash)
handler.verify(OTHER, hash)
return helper
@@ -243,20 +244,20 @@ def test_ldap_salted_md5():
@benchmark.constructor()
def test_phpass():
"""test phpass"""
- from passlib.hash import phpass as handler
- kwds = dict(salt='.'*8, rounds=16)
+ from passlib.hash import phpass
+ handler = phpass.replace(salt='.'*8, rounds=16)
def helper():
- hash = handler.hash(SECRET, **kwds)
+ hash = handler.hash(SECRET)
handler.verify(SECRET, hash)
handler.verify(OTHER, hash)
return helper
@benchmark.constructor()
def test_sha1_crypt():
- from passlib.hash import sha1_crypt as handler
- kwds = dict(salt='.'*8, rounds=10000)
+ from passlib.hash import sha1_crypt
+ handler = sha1_crypt.replace(salt='.'*8, rounds=10000)
def helper():
- hash = handler.hash(SECRET, **kwds)
+ hash = handler.hash(SECRET)
handler.verify(SECRET, hash)
handler.verify(OTHER, hash)
return helper