diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2012-05-01 12:42:43 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2012-05-01 12:42:43 -0400 |
| commit | 7d4769b401b4fea8e21062e6e85503f20989aabd (patch) | |
| tree | 23efda80cf128f79e475bc38054ce3c45ae219a8 /passlib | |
| parent | 3fa87b2933ba2f596297297f97b8fc3e335ba581 (diff) | |
| download | passlib-7d4769b401b4fea8e21062e6e85503f20989aabd.tar.gz | |
loads of documentation updates
Diffstat (limited to 'passlib')
| -rw-r--r-- | passlib/apache.py | 66 | ||||
| -rw-r--r-- | passlib/handlers/cisco.py | 2 | ||||
| -rw-r--r-- | passlib/handlers/oracle.py | 2 | ||||
| -rw-r--r-- | passlib/handlers/postgres.py | 2 | ||||
| -rw-r--r-- | passlib/utils/__init__.py | 80 | ||||
| -rw-r--r-- | passlib/utils/pbkdf2.py | 21 |
6 files changed, 123 insertions, 50 deletions
diff --git a/passlib/apache.py b/passlib/apache.py index 58e0a84..ce4dbb9 100644 --- a/passlib/apache.py +++ b/passlib/apache.py @@ -415,7 +415,7 @@ class HtpasswdFile(_CommonFile): a new htpasswd file, applications can set ``new=True`` so that the existing file (if any) will not be loaded. - .. versionchanged:: 1.6 + .. versionadded:: 1.6 This feature was previously enabled by setting ``autoload=False``. That alias has been deprecated, and will be removed in Passlib 1.8 @@ -444,7 +444,7 @@ class HtpasswdFile(_CommonFile): Must be one of ``"apr_md5_crypt"``, ``"des_crypt"``, ``"ldap_sha1"``, ``"plaintext"``. It defaults to ``"apr_md5_crypt"``. - .. versionchanged:: 1.6 + .. versionadded:: 1.6 This keyword was previously named ``default``. That alias has been deprecated, and will be removed in Passlib 1.8. @@ -464,6 +464,23 @@ class HtpasswdFile(_CommonFile): will probably not be usuable by another application, and particularly not by Apache. + :param autoload: + Set to ``False`` to prevent the constructor from automatically + loaded the file from disk. + + .. deprecated:: 1.6 + This has been replaced by the *new* keyword. + Instead of setting ``autoload=False``, you should use + ``new=True``. Support for this keyword will be removed + in Passlib 1.8. + + :param default: + Change the default algorithm used to encrypt new passwords. + + .. deprecated:: 1.6 + This has been renamed to *default_scheme* for clarity. + Support for this alias will be removed in Passlib 1.8. + Loading & Saving ================ .. automethod:: load @@ -487,6 +504,19 @@ class HtpasswdFile(_CommonFile): ====================== .. automethod:: from_string + Attributes + ========== + .. attribute:: path + + Path to local file that will be used as the default + for all :meth:`load` and :meth:`save` operations. + May be written to, initialized by the *path* constructor keyword. + + .. attribute:: autosave + + Writeable flag indicating whether changes will be automatically + written to *path*. + Errors ====== :raises ValueError: @@ -697,7 +727,7 @@ class HtdigestFile(_CommonFile): a new htpasswd file, applications can set ``new=True`` so that the existing file (if any) will not be loaded. - .. versionchanged:: 1.6 + .. versionadded:: 1.6 This feature was previously enabled by setting ``autoload=False``. That alias has been deprecated, and will be removed in Passlib 1.8 @@ -720,6 +750,16 @@ class HtdigestFile(_CommonFile): This is also exposed as a readonly instance attribute. + :param autoload: + Set to ``False`` to prevent the constructor from automatically + loaded the file from disk. + + .. deprecated:: 1.6 + This has been replaced by the *new* keyword. + Instead of setting ``autoload=False``, you should use + ``new=True``. Support for this keyword will be removed + in Passlib 1.8. + Loading & Saving ================ .. automethod:: load @@ -745,6 +785,26 @@ class HtdigestFile(_CommonFile): ====================== .. automethod:: from_string + Attributes + ========== + .. attribute:: default_realm + + The default realm that will be used if one is not provided + to methods that require it. By default this is ``None``, + in which case an explicit realm must be provided for every + method call. Can be written to. + + .. attribute:: path + + Path to local file that will be used as the default + for all :meth:`load` and :meth:`save` operations. + May be written to, initialized by the *path* constructor keyword. + + .. attribute:: autosave + + Writeable flag indicating whether changes will be automatically + written to *path*. + Errors ====== :raises ValueError: diff --git a/passlib/handlers/cisco.py b/passlib/handlers/cisco.py index 956a060..3bc90a7 100644 --- a/passlib/handlers/cisco.py +++ b/passlib/handlers/cisco.py @@ -26,7 +26,7 @@ __all__ = [ class cisco_pix(uh.HasUserContext, uh.StaticHandler): """This class implements the password hash used by Cisco PIX firewalls, and follows the :ref:`password-hash-api`. - It has a single round, and relies on the username + It does a single round of hashing, and relies on the username as the salt. The :meth:`~passlib.ifc.PasswordHash.encrypt`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py index 7c028be..08850f0 100644 --- a/passlib/handlers/oracle.py +++ b/passlib/handlers/oracle.py @@ -54,7 +54,7 @@ ORACLE10_MAGIC = b("\x01\x23\x45\x67\x89\xAB\xCD\xEF") class oracle10(uh.HasUserContext, uh.StaticHandler): """This class implements the password hash used by Oracle up to version 10g, and follows the :ref:`password-hash-api`. - It has no salt and a single fixed round. + It does a single round of hashing, and relies on the username as the salt. The :meth:`~passlib.ifc.PasswordHash.encrypt`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the following additional contextual keywords: diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py index bb555ec..1324d83 100644 --- a/passlib/handlers/postgres.py +++ b/passlib/handlers/postgres.py @@ -24,7 +24,7 @@ __all__ = [ class postgres_md5(uh.HasUserContext, uh.StaticHandler): """This class implements the Postgres MD5 Password hash, and follows the :ref:`password-hash-api`. - It has no salt and a single fixed round. + It does a single round of hashing, and relies on the username as the salt. The :meth:`~passlib.ifc.PasswordHash.encrypt`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the following additional contextual keywords: diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index a40b744..3e503a2 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -244,7 +244,7 @@ class memoized_property(object): #============================================================================= def consteq(left, right): - """check two strings/bytes for equality, taking constant time relative + """Check two strings/bytes for equality, taking constant time relative to the size of the righthand input. The purpose of this function is to aid in preventing timing attacks @@ -316,7 +316,7 @@ def splitcomma(source, sep=","): return [ elem.strip() for elem in source.split(sep) ] def saslprep(source, param="value"): - """normalizes unicode string using SASLPrep stringprep profile. + """Normalizes unicode string using SASLPrep stringprep profile. The SASLPrep profile is defined in :rfc:`4013`. It provides a uniform scheme for normalizing unicode usernames @@ -443,18 +443,16 @@ if stringprep is None: # pragma: no cover -- runtime detection # bytes helpers #============================================================================= def render_bytes(source, *args): - """helper for using formatting operator with bytes. - - this function is motivated by the fact that - :class:`bytes` instances do not support % or {} formatting under python 3. - this function is an attempt to provide a replacement - that will work uniformly under python 2 & 3. + """Peform ``%`` formating using bytes in a uniform manner across Python 2/3. + This function is motivated by the fact that + :class:`bytes` instances do not support ``%`` or ``{}`` formatting under Python 3. + This function is an attempt to provide a replacement: it converts everything to unicode (decode bytes instances as latin-1), performs the required formatting, then encodes the result to latin-1. - calling ``render_bytes(source, *args)`` should function roughly the same as - ``source % args`` under python 2. + Calling ``render_bytes(source, *args)`` should function roughly the same as + ``source % args`` under Python 2. """ if isinstance(source, bytes): source = source.decode("latin-1") @@ -481,10 +479,10 @@ else: return unhexlify(('%%0%dx' % (count<<1)) % value) add_doc(bytes_to_int, "decode byte string as single big-endian integer") -add_doc(int_to_bytes, "encode intger as single big-endian byte string") +add_doc(int_to_bytes, "encode integer as single big-endian byte string") def xor_bytes(left, right): - "perform bitwise-xor of two byte strings" + "Perform bitwise-xor of two byte strings (must be same size)" return int_to_bytes(bytes_to_int(left) ^ bytes_to_int(right), len(left)) def repeat_string(source, size): @@ -520,7 +518,7 @@ def is_ascii_codec(codec): return _ASCII_TEST_UNICODE.encode(codec) == _ASCII_TEST_BYTES def is_same_codec(left, right): - "check if two codec names are aliases for same codec" + "Check if two codec names are aliases for same codec" if left == right: return True if not (left and right): @@ -530,12 +528,12 @@ def is_same_codec(left, right): _B80 = b('\x80')[0] _U80 = u('\x80') def is_ascii_safe(source): - "check if source (bytes or unicode) contains only 7-bit ascii" + "Check if string (bytes or unicode) contains only 7-bit ascii" r = _B80 if isinstance(source, bytes) else _U80 return all(c < r for c in source) def to_bytes(source, encoding="utf-8", param="value", source_encoding=None): - """helper to normalize input to bytes. + """Helper to normalize input to bytes. :arg source: Source bytes/unicode to process. @@ -571,13 +569,13 @@ def to_bytes(source, encoding="utf-8", param="value", source_encoding=None): else: raise ExpectedStringError(source, param) -def to_unicode(source, source_encoding="utf-8", param="value"): - """helper to normalize input to unicode. +def to_unicode(source, encoding="utf-8", param="value"): + """Helper to normalize input to unicode. :arg source: source bytes/unicode to process. - :arg source_encoding: + :arg encoding: encoding to use when decoding bytes instances. :param param: @@ -587,13 +585,13 @@ def to_unicode(source, source_encoding="utf-8", param="value"): :returns: * returns unicode strings unchanged. - * returns bytes strings decoded using *source_encoding* + * returns bytes strings decoded using *encoding* """ - assert source_encoding + assert encoding if isinstance(source, unicode): return source elif isinstance(source, bytes): - return source.decode(source_encoding) + return source.decode(encoding) else: raise ExpectedStringError(source, param) @@ -615,10 +613,10 @@ else: raise ExpectedStringError(source, param) add_doc(to_native_str, - """take in unicode or bytes, return native string. + """Take in unicode or bytes, return native string. - python 2: encodes unicode using specified encoding, leaves bytes alone. - python 3: leaves unicode alone, decodes bytes using specified encoding. + Python 2: encodes unicode using specified encoding, leaves bytes alone. + Python 3: leaves unicode alone, decodes bytes using specified encoding. :raises TypeError: if source is not unicode or bytes. @@ -645,28 +643,42 @@ def to_hash_str(source, encoding="ascii"): # pragma: no cover -- deprecated & un #================================================================================= class Base64Engine(object): - """provides routines for encoding/decoding base64 data using + """Provides routines for encoding/decoding base64 data using arbitrary character mappings, selectable endianness, etc. :arg charmap: A string of 64 unique characters, - which will be used to encode successive 6-bit chunks. - A character's position within the string will correspond + which will be used to encode successive 6-bit chunks of data. + A character's position within the string should correspond to it's 6-bit value. :param big: Whether the encoding should be big-endian (default False). + .. note:: + This class does not currently handle base64's padding characters + in any way what so ever. + Raw Bytes <-> Encoded Bytes =========================== + The following methods convert between raw bytes, + and strings encoded using the engine's specific base64 variant: + .. automethod:: encode_bytes .. automethod:: decode_bytes .. automethod:: encode_transposed_bytes .. automethod:: decode_transposed_bytes - .. automethod:: check_repair_unused + + .. + .. automethod:: check_repair_unused + .. automethod:: repair_unused Integers <-> Encoded Bytes ========================== + The following methods allow encoding and decoding + unsigned integers to and from the engine's specific base64 variant. + Endianess is determined by the engine's ``big`` constructor keyword. + .. automethod:: encode_int6 .. automethod:: decode_int6 @@ -757,7 +769,7 @@ class Base64Engine(object): # encoding byte strings #============================================================= def encode_bytes(self, source): - """encode bytes to engine's specific base64 variant. + """encode bytes to base64 string. :arg source: byte string to encode. :returns: byte string containing encoded data. @@ -860,7 +872,7 @@ class Base64Engine(object): #============================================================= def decode_bytes(self, source): - """decode bytes from engine's specific base64 variant. + """decode bytes from base64 string. :arg source: byte string to decode. :returns: byte string containing decoded data. @@ -1060,7 +1072,7 @@ class Base64Engine(object): # integer decoding helpers - mainly used by des_crypt family #============================================================= def _decode_int(self, source, bits): - """decode hash64 string -> integer + """decode base64 string -> integer :arg source: base64 string to decode. :arg bits: number of bits in resulting integer. @@ -1114,7 +1126,7 @@ class Base64Engine(object): raise ValueError("invalid character") def decode_int12(self, source): - "decodes 2 char string -> 12-bit integer (little-endian order)" + "decodes 2 char string -> 12-bit integer" if not isinstance(source, bytes): raise TypeError("source must be bytes, not %s" % (type(source),)) if len(source) != 2: @@ -1129,7 +1141,7 @@ class Base64Engine(object): raise ValueError("invalid character") def decode_int24(self, source): - "decodes 4 char string -> 24-bit integer (little-endian order)" + "decodes 4 char string -> 24-bit integer" if not isinstance(source, bytes): raise TypeError("source must be bytes, not %s" % (type(source),)) if len(source) != 4: @@ -1349,7 +1361,7 @@ else: return None return result -add_doc(safe_crypt, """wrapper around stdlib's crypt. +add_doc(safe_crypt, """Wrapper around stdlib's crypt. This is a wrapper around stdlib's :func:`!crypt.crypt`, which attempts to provide uniform behavior across Python 2 and 3. diff --git a/passlib/utils/pbkdf2.py b/passlib/utils/pbkdf2.py index b2d3b23..916b295 100644 --- a/passlib/utils/pbkdf2.py +++ b/passlib/utils/pbkdf2.py @@ -59,18 +59,18 @@ _nhn_hash_names = [ _nhn_cache = {} def norm_hash_name(name, format="hashlib"): - """normalize hash function name + """Normalize hash function name :arg name: - un-normalized hash function name. + Original hash function name. - this name can be a Python :mod:`~hashlib` digest name, - a SCRAM mechanism name, IANA assigned hash name, etc; - case is ignored, underscores converted to hyphens. + This name can be a Python :mod:`~hashlib` digest name, + a SCRAM mechanism name, IANA assigned hash name, etc. + Case is ignored, and underscores are converted to hyphens. :param format: - naming convention to normalize hash names to. - possible values are: + Naming convention to normalize to. + Possible values are: * ``"hashlib"`` (the default) - normalizes name to be compatible with Python's :mod:`!hashlib`. @@ -80,7 +80,7 @@ def norm_hash_name(name, format="hashlib"): and then uses a heuristic to give a "best guess". :returns: - hash name, returned as native string. + Hash name, returned as native :class:`!str`. """ # check cache try: @@ -303,6 +303,7 @@ def pbkdf1(secret, salt, rounds, keylen=None, hash="sha1"): # NOTE: if hash unknown, new() will throw ValueError, which we'd just # reraise anyways; so instead of checking, we just let it get # thrown during first use, below + # TODO: use builtin md4 class if hashlib doesn't have it. def hash_const(msg): return hashlib.new(hash, msg) @@ -343,11 +344,11 @@ def pbkdf2(secret, salt, rounds, keylen=None, prf="hmac-sha1"): :param rounds: number of rounds to use to generate key :arg keylen: number of bytes to generate. - if set to `None``, will use digest size of selected prf. + if set to ``None``, will use digest size of selected prf. :param prf: psuedo-random family to use for key strengthening. this can be any string or callable accepted by :func:`get_prf`. - this defaults to ``hmac-sha1`` (the only prf explicitly listed in + this defaults to ``"hmac-sha1"`` (the only prf explicitly listed in the PBKDF2 specification) :returns: |
