summaryrefslogtreecommitdiff
path: root/passlib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'passlib/utils')
-rw-r--r--passlib/utils/__init__.py9
-rw-r--r--passlib/utils/handlers.py2
2 files changed, 10 insertions, 1 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index e8e5b27..785afe0 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -481,6 +481,15 @@ def int_to_bytes(value, count):
for s in irange(8*count-8,-8,-8)
)
+def repeat_bytes(source, size):
+ "repeat or truncate <source> bytes, so it has length <size>"
+ cur = len(source)
+ if size <= cur:
+ return source[:size]
+ else:
+ mult = (size+cur-1)//cur
+ return (source*mult)[:size]
+
#=============================================================================
# encoding helpers
#=============================================================================
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index abd975d..ea8674c 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -113,7 +113,7 @@ def parse_mc3(hash, prefix, sep=_UDOLLAR, rounds_base=10,
default_rounds=None, handler=None):
"""parse hash using 3-part modular crypt format.
- this expects a hash of the format :samp:`{prefix}[{rounds}$]{salt}[${checksum}]`,
+ this expects a hash of the format :samp:`{prefix}[{rounds}]${salt}[${checksum}]`,
such as sha1_crypt, and parses it into rounds / salt / checksum portions.
tries to convert the rounds to an integer,
and throws error if it has zero-padding.