diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2012-04-17 23:14:51 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2012-04-17 23:14:51 -0400 |
commit | 64ab6fc89b497efa9169f11d55251e417c4db0ba (patch) | |
tree | b3f6f5dc27b87a6bc90cb3686fa98239ee8ff053 /passlib/exc.py | |
parent | 8eb4c4d3b58eec6802c698ddbf357b2fd243a68c (diff) | |
parent | cd029846fdc0c3d7ffc7f53caad4579e7e0e8725 (diff) | |
download | passlib-ironpython-support-dev.tar.gz |
Merge from defaultironpython-support-dev
Diffstat (limited to 'passlib/exc.py')
-rw-r--r-- | passlib/exc.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/passlib/exc.py b/passlib/exc.py index 1e78123..5f7d1dd 100644 --- a/passlib/exc.py +++ b/passlib/exc.py @@ -48,10 +48,10 @@ class PasslibConfigWarning(PasslibWarning): This occurs primarily in one of two cases: - * the policy contains rounds limits which exceed the hard limits + * the CryptContext contains rounds limits which exceed the hard limits imposed by the underlying algorithm. * an explicit rounds value was provided which exceeds the limits - imposed by the policy. + imposed by the CryptContext. In both of these cases, the code will perform correctly & securely; but the warning is issued as a sign the configuration may need updating. @@ -102,17 +102,25 @@ def _get_name(handler): #---------------------------------------------------------------- # encrypt/verify parameter errors #---------------------------------------------------------------- -def ExpectedStringError(value, param): - "error message when param was supposed to be unicode or bytes" - # NOTE: value is never displayed, since it may sometimes be a password. +def type_name(value): + "return pretty-printed string containing name of value's type" cls = value.__class__ if cls.__module__ and cls.__module__ not in ["__builtin__", "builtins"]: - name = "%s.%s" % (cls.__module__, cls.__name__) + return "%s.%s" % (cls.__module__, cls.__name__) elif value is None: - name = 'None' + return 'None' else: - name = cls.__name__ - return TypeError("%s must be unicode or bytes, not %s" % (param, name)) + return cls.__name__ + +def ExpectedTypeError(value, expected, param): + "error message when param was supposed to be one type, but found another" + # NOTE: value is never displayed, since it may sometimes be a password. + name = type_name(value) + return TypeError("%s must be %s, not %s" % (param, expected, name)) + +def ExpectedStringError(value, param): + "error message when param was supposed to be unicode or bytes" + return ExpectedTypeError(value, "unicode or bytes", param) def MissingDigestError(handler=None): "raised when verify() method gets passed config string instead of hash" |