summaryrefslogtreecommitdiff
path: root/passlib/utils
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2011-03-28 00:16:59 -0400
committerEli Collins <elic@assurancetechnologies.com>2011-03-28 00:16:59 -0400
commiteeb244787205ba1139ad8cf971bfd939af8bbbd0 (patch)
tree6367e10989703f8022a25f9c533ca84ea9706455 /passlib/utils
parent7c7bcf5d4eb3cc929bb7ab4411515dd042d0f0e5 (diff)
downloadpasslib-eeb244787205ba1139ad8cf971bfd939af8bbbd0.tar.gz
added support for a bunch of PBKDF2 hash schemes
* pbkdf2_sha1, pbkdf2_sha256, pbkdf2_sha512 -- 3 custom schemes defined by passlib * dlitz_pbkdf2_sha1 -- Dwayne Litzenberger's PBKDF2 crypt * grub_pbkdf2_sha512 -- Grub2's PBKDF2 hash format * two util support functions: adapted_b64_(encode|decode) * UTs and docs for all of the above
Diffstat (limited to 'passlib/utils')
-rw-r--r--passlib/utils/__init__.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index 0d9570d..d387602 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -3,6 +3,7 @@
#imports
#=================================================================================
#core
+from base64 import b64encode, b64decode
from cStringIO import StringIO
from functools import update_wrapper
from hashlib import sha256
@@ -316,6 +317,40 @@ def xor_bytes(left, right):
return _join(chr(ord(l) ^ ord(r)) for l, r in zip(left, right))
#=================================================================================
+#alt base64 encoding
+#=================================================================================
+
+def adapted_b64_encode(data):
+ """encode using variant of base64
+
+ the output of this function is identical to b64_encode,
+ except that it uses ``.`` instead of ``+``,
+ and omits trailing padding ``=`` and whitepsace.
+
+ it is primarily used for by passlib's custom pbkdf2 hashes.
+ """
+ return b64encode(data, "./").strip("=\n")
+
+def adapted_b64_decode(data, sixthree="."):
+ """decode using variant of base64
+
+ the input of this function is identical to b64_decode,
+ except that it uses ``.`` instead of ``+``,
+ and should not include trailing padding ``=`` or whitespace.
+
+ it is primarily used for by passlib's custom pbkdf2 hashes.
+ """
+ off = len(data) % 4
+ if off == 0:
+ return b64decode(data, "./")
+ elif off == 1:
+ raise ValueError, "invalid bas64 input"
+ elif off == 2:
+ return b64decode(data + "==", "./")
+ else:
+ return b64decode(data + "=", "./")
+
+#=================================================================================
#randomness
#=================================================================================