summaryrefslogtreecommitdiff
path: root/passlib/utils
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2011-06-17 23:26:28 -0400
committerEli Collins <elic@assurancetechnologies.com>2011-06-17 23:26:28 -0400
commit4e26763cd57da1e7feeaa5568f535acc85418948 (patch)
treebd5a4241e7ecb0af06495fdaf74d89970e3d40a7 /passlib/utils
parente1cad3f31308c0d6bc2928978a771bfc885a3e5f (diff)
downloadpasslib-4e26763cd57da1e7feeaa5568f535acc85418948.tar.gz
pbkdf2 handlers now py3 compat
Diffstat (limited to 'passlib/utils')
-rw-r--r--passlib/utils/__init__.py12
-rw-r--r--passlib/utils/handlers.py6
2 files changed, 14 insertions, 4 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index e444383..ab5826b 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -498,6 +498,10 @@ def xor_bytes(left, right):
#=================================================================================
#alt base64 encoding
#=================================================================================
+_A64_ALTCHARS = b("./")
+_A64_STRIP = b("=\n")
+_A64_PAD1 = b("=")
+_A64_PAD2 = b("==")
def adapted_b64_encode(data):
"""encode using variant of base64
@@ -508,7 +512,7 @@ def adapted_b64_encode(data):
it is primarily used for by passlib's custom pbkdf2 hashes.
"""
- return b64encode(data, "./").strip("=\n")
+ return b64encode(data, _A64_ALTCHARS).strip(_A64_STRIP)
def adapted_b64_decode(data, sixthree="."):
"""decode using variant of base64
@@ -521,13 +525,13 @@ def adapted_b64_decode(data, sixthree="."):
"""
off = len(data) % 4
if off == 0:
- return b64decode(data, "./")
+ return b64decode(data, _A64_ALTCHARS)
elif off == 1:
raise ValueError("invalid bas64 input")
elif off == 2:
- return b64decode(data + "==", "./")
+ return b64decode(data + _A64_PAD2, _A64_ALTCHARS)
else:
- return b64decode(data + "=", "./")
+ return b64decode(data + _A64_PAD1, _A64_ALTCHARS)
#=================================================================================
#randomness
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index b06a9eb..c15deb6 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -366,6 +366,12 @@ class GenericHandler(object):
should return native string type (ascii-bytes under python 2,
unicode under python 3)
"""
+ #NOTE: documenting some non-standardized but common kwd flags
+ # that passlib to_string() method may have
+ #
+ # native=True -- if false, return unicode under py2 -- ignored under py3
+ # withchk=True -- if false, omit checksum portion of hash
+ #
raise NotImplementedError("%s must implement from_string()" % (type(self),))
##def to_config_string(self):