summaryrefslogtreecommitdiff
path: root/passlib
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2012-02-08 23:32:13 -0500
committerEli Collins <elic@assurancetechnologies.com>2012-02-08 23:32:13 -0500
commitdcd2dcc7243052b2d5bd7d9f4abbedbb01911e13 (patch)
treea154bbd8263d86e0f39617bf14eb0cff0fa622b3 /passlib
parent4712bcd50e12e8ed2e8c135d88ed49951dd45bdf (diff)
downloadpasslib-dcd2dcc7243052b2d5bd7d9f4abbedbb01911e13.tar.gz
renamed calc_checksum() -> _calc_checksum(), hiding the last of the private methods of most handlers
Diffstat (limited to 'passlib')
-rw-r--r--passlib/handlers/des_crypt.py4
-rw-r--r--passlib/handlers/django.py8
-rw-r--r--passlib/handlers/fshp.py2
-rw-r--r--passlib/handlers/ldap_digests.py2
-rw-r--r--passlib/handlers/md5_crypt.py4
-rw-r--r--passlib/handlers/nthash.py2
-rw-r--r--passlib/handlers/oracle.py2
-rw-r--r--passlib/handlers/pbkdf2.py10
-rw-r--r--passlib/handlers/phpass.py2
-rw-r--r--passlib/handlers/scram.py6
-rw-r--r--passlib/handlers/sun_md5_crypt.py2
-rw-r--r--passlib/tests/test_utils_handlers.py8
-rw-r--r--passlib/utils/handlers.py34
13 files changed, 43 insertions, 43 deletions
diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py
index a5582f6..6b3c436 100644
--- a/passlib/handlers/des_crypt.py
+++ b/passlib/handlers/des_crypt.py
@@ -422,7 +422,7 @@ class bigcrypt(uh.HasSalt, uh.GenericHandler):
#=========================================================
#TODO: check if os_crypt supports ext-des-crypt.
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
chk = raw_crypt(secret, self.salt.encode("ascii"))
@@ -500,7 +500,7 @@ class crypt16(uh.HasSalt, uh.GenericHandler):
#=========================================================
#TODO: check if os_crypt supports ext-des-crypt.
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
diff --git a/passlib/handlers/django.py b/passlib/handlers/django.py
index 8ead857..901a0a0 100644
--- a/passlib/handlers/django.py
+++ b/passlib/handlers/django.py
@@ -90,7 +90,7 @@ class django_salted_sha1(DjangoSaltedHash):
checksum_size = 40
_stub_checksum = u('0') * 40
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
return str_to_uascii(sha1(self.salt.encode("ascii") + secret).hexdigest())
@@ -116,7 +116,7 @@ class django_salted_md5(DjangoSaltedHash):
checksum_size = 32
_stub_checksum = u('0') * 32
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
return str_to_uascii(md5(self.salt.encode("ascii") + secret).hexdigest())
@@ -177,14 +177,14 @@ class django_des_crypt(DjangoSaltedHash):
else:
return stub
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
# NOTE: we lazily import des_crypt,
# since most django deploys won't use django_des_crypt
global des_crypt
if des_crypt is None:
_import_des_crypt()
salt = self.salt[:2]
- return salt + des_crypt(salt=salt).calc_checksum(secret)
+ return salt + des_crypt(salt=salt)._calc_checksum(secret)
class django_disabled(uh.StaticHandler):
"""This class provides disabled password behavior for Django, and follows the :ref:`password-hash-api`.
diff --git a/passlib/handlers/fshp.py b/passlib/handlers/fshp.py
index adf853d..6141d4e 100644
--- a/passlib/handlers/fshp.py
+++ b/passlib/handlers/fshp.py
@@ -170,7 +170,7 @@ class fshp(uh.HasStubChecksum, uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, u
#backend
#=========================================================
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
#NOTE: for some reason, FSHP uses pbkdf1 with password & salt reversed.
diff --git a/passlib/handlers/ldap_digests.py b/passlib/handlers/ldap_digests.py
index 176ec35..38fe002 100644
--- a/passlib/handlers/ldap_digests.py
+++ b/passlib/handlers/ldap_digests.py
@@ -96,7 +96,7 @@ class _SaltedBase64DigestHelper(uh.HasStubChecksum, uh.HasRawSalt, uh.HasRawChec
hash = self.ident + b64encode(data).decode("ascii")
return uascii_to_str(hash)
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if secret is None:
raise TypeError("no secret provided")
if isinstance(secret, unicode):
diff --git a/passlib/handlers/md5_crypt.py b/passlib/handlers/md5_crypt.py
index 59ba814..50f1c0d 100644
--- a/passlib/handlers/md5_crypt.py
+++ b/passlib/handlers/md5_crypt.py
@@ -181,7 +181,7 @@ class _Md5Common(uh.HasSalt, uh.GenericHandler):
#=========================================================
#primary interface
#=========================================================
- #calc_checksum in subclass
+ # calc_checksum defined in subclass
#=========================================================
#eoc
@@ -267,7 +267,7 @@ class apr_md5_crypt(_Md5Common):
#=========================================================
#primary interface
#=========================================================
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
return raw_md5_crypt(secret, self.salt, apr=True)
#=========================================================
diff --git a/passlib/handlers/nthash.py b/passlib/handlers/nthash.py
index b3cd947..6ad56c2 100644
--- a/passlib/handlers/nthash.py
+++ b/passlib/handlers/nthash.py
@@ -76,7 +76,7 @@ class nthash(uh.HasStubChecksum, uh.HasManyIdents, uh.GenericHandler):
#primary interface
#=========================================================
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
return self.raw_nthash(secret, hex=True)
@staticmethod
diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py
index 68dc138..61ad27a 100644
--- a/passlib/handlers/oracle.py
+++ b/passlib/handlers/oracle.py
@@ -182,7 +182,7 @@ class oracle11(uh.HasStubChecksum, uh.HasSalt, uh.GenericHandler):
hash = u("S:%s%s") % (chk.upper(), self.salt.upper())
return uascii_to_str(hash)
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
chk = sha1(secret + unhexlify(self.salt.encode("ascii"))).hexdigest()
diff --git a/passlib/handlers/pbkdf2.py b/passlib/handlers/pbkdf2.py
index 96cd47a..37dab77 100644
--- a/passlib/handlers/pbkdf2.py
+++ b/passlib/handlers/pbkdf2.py
@@ -88,7 +88,7 @@ class Pbkdf2DigestHandler(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gen
hash = u('%s%d$%s') % (self.ident, self.rounds, salt)
return uascii_to_str(hash)
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
return pbkdf2(secret, self.salt, self.rounds, self.checksum_size, self._prf)
@@ -229,7 +229,7 @@ class cta_pbkdf2_sha1(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Generic
#=========================================================
#backend
#=========================================================
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
return pbkdf2(secret, self.salt, self.rounds, 20, "hmac-sha1")
@@ -322,7 +322,7 @@ class dlitz_pbkdf2_sha1(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
#=========================================================
#backend
#=========================================================
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
salt = str_to_bascii(self.to_string(withchk=False))
@@ -377,7 +377,7 @@ class atlassian_pbkdf2_sha1(uh.HasStubChecksum, uh.HasRawSalt, uh.HasRawChecksum
hash = self.ident + b64encode(data).decode("ascii")
return uascii_to_str(hash)
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
#TODO: find out what crowd's policy is re: unicode
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
@@ -450,7 +450,7 @@ class grub_pbkdf2_sha512(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gene
hash = u('%s%d.%s') % (self.ident, self.rounds, salt)
return uascii_to_str(hash)
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
#TODO: find out what grub's policy is re: unicode
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
diff --git a/passlib/handlers/phpass.py b/passlib/handlers/phpass.py
index 19486a9..3273d61 100644
--- a/passlib/handlers/phpass.py
+++ b/passlib/handlers/phpass.py
@@ -114,7 +114,7 @@ class phpass(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.GenericHandler):
#=========================================================
#backend
#=========================================================
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
#FIXME: can't find definitive policy on how phpass handles non-ascii.
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
diff --git a/passlib/handlers/scram.py b/passlib/handlers/scram.py
index ce972e5..1c31562 100644
--- a/passlib/handlers/scram.py
+++ b/passlib/handlers/scram.py
@@ -442,7 +442,7 @@ class scram(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
return not algs.issubset(cls.from_string(hash).algs)
return detector
- def calc_checksum(self, secret, alg=None):
+ def _calc_checksum(self, secret, alg=None):
rounds = self.rounds
salt = self.salt
hash = self.derive_digest
@@ -470,7 +470,7 @@ class scram(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
if full_verify:
correct = failed = False
for alg, digest in iteritems(chkmap):
- other = self.calc_checksum(secret, alg)
+ other = self._calc_checksum(secret, alg)
# NOTE: could do this length check in norm_algs(),
# but don't need to be that strict, and want to be able
# to parse hashes containing algs not supported by platform.
@@ -491,7 +491,7 @@ class scram(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
# otherwise only verify against one hash, pick one w/ best security.
for alg in self._verify_algs:
if alg in chkmap:
- other = self.calc_checksum(secret, alg)
+ other = self._calc_checksum(secret, alg)
return consteq(other, chkmap[alg])
# there should *always* be at least sha-1.
raise AssertionError("sha-1 digest not found!")
diff --git a/passlib/handlers/sun_md5_crypt.py b/passlib/handlers/sun_md5_crypt.py
index 31ba01e..24d3007 100644
--- a/passlib/handlers/sun_md5_crypt.py
+++ b/passlib/handlers/sun_md5_crypt.py
@@ -326,7 +326,7 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler):
# actually behaves correctly.
# especially, when using ''-config, make sure to append '$x' to string.
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
#NOTE: no reference for how sun_md5_crypt handles unicode
if secret is None:
raise TypeError("no secret specified")
diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py
index 148228b..39791ca 100644
--- a/passlib/tests/test_utils_handlers.py
+++ b/passlib/tests/test_utils_handlers.py
@@ -298,12 +298,12 @@ class SkeletonTest(TestCase):
#test lazy load
obj = d1()
- self.assertEqual(obj.calc_checksum('s'), 'b')
+ self.assertEqual(obj._calc_checksum('s'), 'b')
#test repeat load
d1.set_backend('b')
d1.set_backend('any')
- self.assertEqual(obj.calc_checksum('s'), 'b')
+ self.assertEqual(obj._calc_checksum('s'), 'b')
#test unavailable
self.assertRaises(MissingBackendError, d1.set_backend, 'a')
@@ -316,7 +316,7 @@ class SkeletonTest(TestCase):
#test explicit
self.assertTrue(d1.has_backend())
d1.set_backend('a')
- self.assertEqual(obj.calc_checksum('s'), 'a')
+ self.assertEqual(obj._calc_checksum('s'), 'a')
#test unknown backend
self.assertRaises(ValueError, d1.set_backend, 'c')
@@ -532,7 +532,7 @@ class SaltedHash(uh.HasStubChecksum, uh.HasSalt, uh.GenericHandler):
hash = u("@salt%s%s") % (self.salt, self.checksum or self._stub_checksum)
return uascii_to_str(hash)
- def calc_checksum(self, secret):
+ def _calc_checksum(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
data = self.salt.encode("ascii") + secret + self.salt.encode("ascii")
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index f404b47..139143b 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -343,7 +343,7 @@ class GenericHandler(object):
.. automethod:: from_string
.. automethod:: to_string
- .. automethod:: calc_checksum
+ .. automethod:: _calc_checksum
Default Methods
===============
@@ -497,14 +497,14 @@ class GenericHandler(object):
@classmethod
def genhash(cls, secret, config):
self = cls.from_string(config)
- self.checksum = self.calc_checksum(secret)
+ self.checksum = self._calc_checksum(secret)
return self.to_string()
- def calc_checksum(self, secret): #pragma: no cover
+ def _calc_checksum(self, secret): #pragma: no cover
"""given secret; calcuate and return encoded checksum portion of hash
string, taking config from object state
"""
- raise NotImplementedError("%s must implement calc_checksum()" %
+ raise NotImplementedError("%s must implement _calc_checksum()" %
(self.__class__,))
#=========================================================
@@ -513,7 +513,7 @@ class GenericHandler(object):
@classmethod
def encrypt(cls, secret, **settings):
self = cls(use_defaults=True, **settings)
- self.checksum = self.calc_checksum(secret)
+ self.checksum = self._calc_checksum(secret)
return self.to_string()
@classmethod
@@ -526,7 +526,7 @@ class GenericHandler(object):
if chk is None:
raise ValueError("expected %s hash, got %s config string instead" %
(cls.name, cls.name))
- return consteq(self.calc_checksum(secret), chk)
+ return consteq(self._calc_checksum(secret), chk)
#=========================================================
#eoc
@@ -598,13 +598,13 @@ class HasStubChecksum(GenericHandler):
## self = cls()
## else:
## self = cls.from_string(config) #just to validate the input
-## self.checksum = self.calc_checksum(secret)
+## self.checksum = self._calc_checksum(secret)
## return self.to_string()
##
## @classmethod
## def encrypt(cls, secret):
## self = cls()
-## self.checksum = self.calc_checksum(secret)
+## self.checksum = self._calc_checksum(secret)
## return self.to_string()
class HasManyIdents(GenericHandler):
@@ -1048,7 +1048,7 @@ def _clear_backend(cls):
assert issubclass(cls, HasManyBackends) and cls is not HasManyBackends
if cls._backend:
del cls._backend
- del cls.calc_checksum
+ del cls._calc_checksum
class HasManyBackends(GenericHandler):
"""GenericHandler mixin which provides selecting from multiple backends.
@@ -1059,7 +1059,7 @@ class HasManyBackends(GenericHandler):
For hashes which need to select from multiple backends,
depending on the host environment, this class
- offers a way to specify alternate :meth:`calc_checksum` methods,
+ offers a way to specify alternate :meth:`_calc_checksum` methods,
and will dynamically chose the best one at runtime.
Backend Methods
@@ -1090,7 +1090,7 @@ class HasManyBackends(GenericHandler):
.. classmethod:: _calc_checksum_{name}
- private class method that should implement :meth:`calc_checksum`
+ private class method that should implement :meth:`_calc_checksum`
for a given backend. it will only be called if the backend has
been selected by :meth:`set_backend`. One of these should be provided
by the subclass for each backend listed in :attr:`backends`.
@@ -1154,9 +1154,9 @@ class HasManyBackends(GenericHandler):
@classmethod
def set_backend(cls, name="any"):
- """load specified backend to be used for future calc_checksum() calls
+ """load specified backend to be used for future _calc_checksum() calls
- this method replaces :meth:`calc_checksum` with a method
+ this method replaces :meth:`_calc_checksum` with a method
which uses the specified backend.
:arg name:
@@ -1199,19 +1199,19 @@ class HasManyBackends(GenericHandler):
raise MissingBackendError(cls._no_backends_msg())
elif not cls.has_backend(name):
raise MissingBackendError("%s backend not available: %r" % (cls.name, name))
- cls.calc_checksum = getattr(cls, "_calc_checksum_" + name)
+ cls._calc_checksum = getattr(cls, "_calc_checksum_" + name)
cls._backend = name
return name
- def calc_checksum(self, secret):
- "stub for calc_checksum(), default backend will be selected first time stub is called"
+ def _calc_checksum(self, secret):
+ "stub for _calc_checksum(), default backend will be selected first time stub is called"
# if we got here, no backend has been loaded; so load default backend
assert not self._backend, "set_backend() failed to replace lazy loader"
self.set_backend()
assert self._backend, "set_backend() failed to load a default backend"
# this should now invoke the backend-specific version, so call it again.
- return self.calc_checksum(secret)
+ return self._calc_checksum(secret)
#=========================================================
#wrappers