mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 18:01:36 +00:00
update googleapiclient, httplib2, oauth2client and passlib to latest versions
This commit is contained in:
@@ -130,7 +130,7 @@ class classproperty(object):
|
||||
|
||||
@property
|
||||
def __func__(self):
|
||||
"py3 compatible alias"
|
||||
"""py3 compatible alias"""
|
||||
return self.im_func
|
||||
|
||||
def deprecated_function(msg=None, deprecated=None, removed=None, updoc=True,
|
||||
@@ -221,7 +221,7 @@ class memoized_property(object):
|
||||
|
||||
@property
|
||||
def __func__(self):
|
||||
"py3 alias"
|
||||
"""py3 alias"""
|
||||
return self.im_func
|
||||
|
||||
# works but not used
|
||||
@@ -253,7 +253,7 @@ def consteq(left, right):
|
||||
|
||||
The purpose of this function is to help prevent timing attacks
|
||||
during digest comparisons: the standard ``==`` operator aborts
|
||||
after the first mismatched character, causing it's runtime to be
|
||||
after the first mismatched character, causing its runtime to be
|
||||
proportional to the longest prefix shared by the two inputs.
|
||||
If an attacker is able to predict and control one of the two
|
||||
inputs, repeated queries can be leveraged to reveal information about
|
||||
@@ -456,7 +456,7 @@ def saslprep(source, param="value"):
|
||||
# replace saslprep() with stub when stringprep is missing
|
||||
if stringprep is None: # pragma: no cover -- runtime detection
|
||||
def saslprep(source, param="value"):
|
||||
"stub for saslprep()"
|
||||
"""stub for saslprep()"""
|
||||
raise NotImplementedError("saslprep() support requires the 'stringprep' "
|
||||
"module, which is " + _stringprep_missing_reason)
|
||||
|
||||
@@ -503,11 +503,11 @@ add_doc(bytes_to_int, "decode byte string as single big-endian integer")
|
||||
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 (must be same size)"
|
||||
"""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):
|
||||
"repeat or truncate <source> string, so it has length <size>"
|
||||
"""repeat or truncate <source> string, so it has length <size>"""
|
||||
cur = len(source)
|
||||
if size > cur:
|
||||
mult = (size+cur-1)//cur
|
||||
@@ -519,7 +519,7 @@ _BNULL = b("\x00")
|
||||
_UNULL = u("\x00")
|
||||
|
||||
def right_pad_string(source, size, pad=None):
|
||||
"right-pad or truncate <source> string, so it has length <size>"
|
||||
"""right-pad or truncate <source> string, so it has length <size>"""
|
||||
cur = len(source)
|
||||
if size > cur:
|
||||
if pad is None:
|
||||
@@ -535,11 +535,11 @@ _ASCII_TEST_BYTES = b("\x00\n aA:#!\x7f")
|
||||
_ASCII_TEST_UNICODE = _ASCII_TEST_BYTES.decode("ascii")
|
||||
|
||||
def is_ascii_codec(codec):
|
||||
"Test if codec is compatible with 7-bit ascii (e.g. latin-1, utf-8; but not utf-16)"
|
||||
"""Test if codec is compatible with 7-bit ascii (e.g. latin-1, utf-8; but not utf-16)"""
|
||||
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):
|
||||
@@ -549,7 +549,7 @@ def is_same_codec(left, right):
|
||||
_B80 = b('\x80')[0]
|
||||
_U80 = u('\x80')
|
||||
def is_ascii_safe(source):
|
||||
"Check if string (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)
|
||||
|
||||
@@ -656,7 +656,7 @@ add_doc(to_native_str,
|
||||
|
||||
@deprecated_function(deprecated="1.6", removed="1.7")
|
||||
def to_hash_str(source, encoding="ascii"): # pragma: no cover -- deprecated & unused
|
||||
"deprecated, use to_native_str() instead"
|
||||
"""deprecated, use to_native_str() instead"""
|
||||
return to_native_str(source, encoding, param="hash")
|
||||
|
||||
#=============================================================================
|
||||
@@ -671,7 +671,7 @@ class Base64Engine(object):
|
||||
A string of 64 unique characters,
|
||||
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.
|
||||
to its 6-bit value.
|
||||
|
||||
:param big:
|
||||
Whether the encoding should be big-endian (default False).
|
||||
@@ -783,7 +783,7 @@ class Base64Engine(object):
|
||||
|
||||
@property
|
||||
def charmap(self):
|
||||
"charmap as unicode"
|
||||
"""charmap as unicode"""
|
||||
return self.bytemap.decode("latin-1")
|
||||
|
||||
#===================================================================
|
||||
@@ -811,7 +811,7 @@ class Base64Engine(object):
|
||||
return out
|
||||
|
||||
def _encode_bytes_little(self, next_value, chunks, tail):
|
||||
"helper used by encode_bytes() to handle little-endian encoding"
|
||||
"""helper used by encode_bytes() to handle little-endian encoding"""
|
||||
#
|
||||
# output bit layout:
|
||||
#
|
||||
@@ -850,7 +850,7 @@ class Base64Engine(object):
|
||||
yield v2>>4
|
||||
|
||||
def _encode_bytes_big(self, next_value, chunks, tail):
|
||||
"helper used by encode_bytes() to handle big-endian encoding"
|
||||
"""helper used by encode_bytes() to handle big-endian encoding"""
|
||||
#
|
||||
# output bit layout:
|
||||
#
|
||||
@@ -916,7 +916,7 @@ class Base64Engine(object):
|
||||
raise ValueError("invalid character: %r" % (err.args[0],))
|
||||
|
||||
def _decode_bytes_little(self, next_value, chunks, tail):
|
||||
"helper used by decode_bytes() to handle little-endian encoding"
|
||||
"""helper used by decode_bytes() to handle little-endian encoding"""
|
||||
#
|
||||
# input bit layout:
|
||||
#
|
||||
@@ -951,7 +951,7 @@ class Base64Engine(object):
|
||||
yield (v2>>2) | ((v3 & 0xF) << 4)
|
||||
|
||||
def _decode_bytes_big(self, next_value, chunks, tail):
|
||||
"helper used by decode_bytes() to handle big-endian encoding"
|
||||
"""helper used by decode_bytes() to handle big-endian encoding"""
|
||||
#
|
||||
# input bit layout:
|
||||
#
|
||||
@@ -993,21 +993,21 @@ class Base64Engine(object):
|
||||
# equivalent char with no padding bits set.
|
||||
|
||||
def __make_padset(self, bits):
|
||||
"helper to generate set of valid last chars & bytes"
|
||||
"""helper to generate set of valid last chars & bytes"""
|
||||
pset = set(c for i,c in enumerate(self.bytemap) if not i & bits)
|
||||
pset.update(c for i,c in enumerate(self.charmap) if not i & bits)
|
||||
return frozenset(pset)
|
||||
|
||||
@memoized_property
|
||||
def _padinfo2(self):
|
||||
"mask to clear padding bits, and valid last bytes (for strings 2 % 4)"
|
||||
"""mask to clear padding bits, and valid last bytes (for strings 2 % 4)"""
|
||||
# 4 bits of last char unused (lsb for big, msb for little)
|
||||
bits = 15 if self.big else (15<<2)
|
||||
return ~bits, self.__make_padset(bits)
|
||||
|
||||
@memoized_property
|
||||
def _padinfo3(self):
|
||||
"mask to clear padding bits, and valid last bytes (for strings 3 % 4)"
|
||||
"""mask to clear padding bits, and valid last bytes (for strings 3 % 4)"""
|
||||
# 2 bits of last char unused (lsb for big, msb for little)
|
||||
bits = 3 if self.big else (3<<4)
|
||||
return ~bits, self.__make_padset(bits)
|
||||
@@ -1072,14 +1072,14 @@ class Base64Engine(object):
|
||||
# transposed encoding/decoding
|
||||
#===================================================================
|
||||
def encode_transposed_bytes(self, source, offsets):
|
||||
"encode byte string, first transposing source using offset list"
|
||||
"""encode byte string, first transposing source using offset list"""
|
||||
if not isinstance(source, bytes):
|
||||
raise TypeError("source must be bytes, not %s" % (type(source),))
|
||||
tmp = join_byte_elems(source[off] for off in offsets)
|
||||
return self.encode_bytes(tmp)
|
||||
|
||||
def decode_transposed_bytes(self, source, offsets):
|
||||
"decode byte string, then reverse transposition described by offset list"
|
||||
"""decode byte string, then reverse transposition described by offset list"""
|
||||
# NOTE: if transposition does not use all bytes of source,
|
||||
# the original can't be recovered... and join_byte_elems() will throw
|
||||
# an error because 1+ values in <buf> will be None.
|
||||
@@ -1133,7 +1133,7 @@ class Base64Engine(object):
|
||||
#---------------------------------------------------------------
|
||||
|
||||
def decode_int6(self, source):
|
||||
"decode single character -> 6 bit integer"
|
||||
"""decode single character -> 6 bit integer"""
|
||||
if not isinstance(source, bytes):
|
||||
raise TypeError("source must be bytes, not %s" % (type(source),))
|
||||
if len(source) != 1:
|
||||
@@ -1147,7 +1147,7 @@ class Base64Engine(object):
|
||||
raise ValueError("invalid character")
|
||||
|
||||
def decode_int12(self, source):
|
||||
"decodes 2 char string -> 12-bit integer"
|
||||
"""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:
|
||||
@@ -1162,7 +1162,7 @@ class Base64Engine(object):
|
||||
raise ValueError("invalid character")
|
||||
|
||||
def decode_int24(self, source):
|
||||
"decodes 4 char string -> 24-bit integer"
|
||||
"""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:
|
||||
@@ -1216,7 +1216,7 @@ class Base64Engine(object):
|
||||
#---------------------------------------------------------------
|
||||
|
||||
def encode_int6(self, value):
|
||||
"encodes 6-bit integer -> single hash64 character"
|
||||
"""encodes 6-bit integer -> single hash64 character"""
|
||||
if value < 0 or value > 63:
|
||||
raise ValueError("value out of range")
|
||||
if PY3:
|
||||
@@ -1225,7 +1225,7 @@ class Base64Engine(object):
|
||||
return self._encode64(value)
|
||||
|
||||
def encode_int12(self, value):
|
||||
"encodes 12-bit integer -> 2 char string"
|
||||
"""encodes 12-bit integer -> 2 char string"""
|
||||
if value < 0 or value > 0xFFF:
|
||||
raise ValueError("value out of range")
|
||||
raw = [value & 0x3f, (value>>6) & 0x3f]
|
||||
@@ -1234,7 +1234,7 @@ class Base64Engine(object):
|
||||
return join_byte_elems(imap(self._encode64, raw))
|
||||
|
||||
def encode_int24(self, value):
|
||||
"encodes 24-bit integer -> 4 char string"
|
||||
"""encodes 24-bit integer -> 4 char string"""
|
||||
if value < 0 or value > 0xFFFFFF:
|
||||
raise ValueError("value out of range")
|
||||
raw = [value & 0x3f, (value>>6) & 0x3f,
|
||||
@@ -1258,7 +1258,7 @@ class Base64Engine(object):
|
||||
#===================================================================
|
||||
|
||||
class LazyBase64Engine(Base64Engine):
|
||||
"Base64Engine which delays initialization until it's accessed"
|
||||
"""Base64Engine which delays initialization until it's accessed"""
|
||||
_lazy_opts = None
|
||||
|
||||
def __init__(self, *args, **kwds):
|
||||
@@ -1331,6 +1331,7 @@ def ab64_decode(data):
|
||||
try:
|
||||
from crypt import crypt as _crypt
|
||||
except ImportError: # pragma: no cover
|
||||
_crypt = None
|
||||
has_crypt = False
|
||||
def safe_crypt(secret, hash):
|
||||
return None
|
||||
@@ -1451,13 +1452,13 @@ except NotImplementedError: # pragma: no cover
|
||||
has_urandom = False
|
||||
|
||||
def genseed(value=None):
|
||||
"generate prng seed value from system resources"
|
||||
"""generate prng seed value from system resources"""
|
||||
from hashlib import sha512
|
||||
text = u("%s %s %s %s %.15f %.15f %s") % (
|
||||
# if caller specified a seed value, mix it in
|
||||
value,
|
||||
|
||||
# if caller's seed value was an RNG, mix in bits from it's state
|
||||
# if caller's seed value was an RNG, mix in bits from its state
|
||||
value.getrandbits(1<<15) if hasattr(value, "getrandbits") else None,
|
||||
|
||||
# add current process id
|
||||
@@ -1572,7 +1573,7 @@ _handler_attrs = (
|
||||
)
|
||||
|
||||
def is_crypt_handler(obj):
|
||||
"check if object follows the :ref:`password-hash-api`"
|
||||
"""check if object follows the :ref:`password-hash-api`"""
|
||||
# XXX: change to use isinstance(obj, PasswordHash) under py26+?
|
||||
return all(hasattr(obj, name) for name in _handler_attrs)
|
||||
|
||||
@@ -1583,7 +1584,7 @@ _context_attrs = (
|
||||
)
|
||||
|
||||
def is_crypt_context(obj):
|
||||
"check if object appears to be a :class:`~passlib.context.CryptContext` instance"
|
||||
"""check if object appears to be a :class:`~passlib.context.CryptContext` instance"""
|
||||
# XXX: change to use isinstance(obj, CryptContext)?
|
||||
return all(hasattr(obj, name) for name in _context_attrs)
|
||||
|
||||
@@ -1593,12 +1594,12 @@ def is_crypt_context(obj):
|
||||
## return hasattr(handler, "set_backend")
|
||||
|
||||
def has_rounds_info(handler):
|
||||
"check if handler provides the optional :ref:`rounds information <rounds-attributes>` attributes"
|
||||
"""check if handler provides the optional :ref:`rounds information <rounds-attributes>` attributes"""
|
||||
return ('rounds' in handler.setting_kwds and
|
||||
getattr(handler, "min_rounds", None) is not None)
|
||||
|
||||
def has_salt_info(handler):
|
||||
"check if handler provides the optional :ref:`salt information <salt-attributes>` attributes"
|
||||
"""check if handler provides the optional :ref:`salt information <salt-attributes>` attributes"""
|
||||
return ('salt' in handler.setting_kwds and
|
||||
getattr(handler, "min_salt_size", None) is not None)
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ This package contains two submodules:
|
||||
|
||||
Status
|
||||
------
|
||||
This implementation is usuable, but is an order of magnitude too slow to be
|
||||
usuable with real security. For "ok" security, BCrypt hashes should have at
|
||||
This implementation is usable, but is an order of magnitude too slow to be
|
||||
usable with real security. For "ok" security, BCrypt hashes should have at
|
||||
least 2**11 rounds (as of 2011). Assuming a desired response time <= 100ms,
|
||||
this means a BCrypt implementation should get at least 20 rounds/ms in order
|
||||
to be both usuable *and* secure. On a 2 ghz cpu, this implementation gets
|
||||
to be both usable *and* secure. On a 2 ghz cpu, this implementation gets
|
||||
roughly 0.09 rounds/ms under CPython (220x too slow), and 1.9 rounds/ms
|
||||
under PyPy (10x too slow).
|
||||
|
||||
@@ -55,7 +55,7 @@ from itertools import chain
|
||||
import struct
|
||||
# pkg
|
||||
from passlib.utils import bcrypt64, getrandbytes, rng
|
||||
from passlib.utils.compat import b, bytes, BytesIO, unicode, u
|
||||
from passlib.utils.compat import b, bytes, BytesIO, unicode, u, native_string_types
|
||||
from passlib.utils._blowfish.unrolled import BlowfishEngine
|
||||
# local
|
||||
__all__ = [
|
||||
@@ -98,19 +98,15 @@ def raw_bcrypt(password, ident, salt, log_rounds):
|
||||
#===================================================================
|
||||
|
||||
# parse ident
|
||||
assert isinstance(ident, unicode)
|
||||
if ident == u('2'):
|
||||
minor = 0
|
||||
elif ident == u('2a'):
|
||||
minor = 1
|
||||
# XXX: how to indicate caller wants to use crypt_blowfish's
|
||||
# workaround variant of 2a?
|
||||
assert isinstance(ident, native_string_types)
|
||||
add_null_padding = True
|
||||
if ident == u('2a') or ident == u('2y') or ident == u('2b'):
|
||||
pass
|
||||
elif ident == u('2'):
|
||||
add_null_padding = False
|
||||
elif ident == u('2x'):
|
||||
raise ValueError("crypt_blowfish's buggy '2x' hashes are not "
|
||||
"currently supported")
|
||||
elif ident == u('2y'):
|
||||
# crypt_blowfish compatibility ident which guarantees compat w/ 2a
|
||||
minor = 1
|
||||
else:
|
||||
raise ValueError("unknown ident: %r" % (ident,))
|
||||
|
||||
@@ -124,7 +120,7 @@ def raw_bcrypt(password, ident, salt, log_rounds):
|
||||
|
||||
# prepare password
|
||||
assert isinstance(password, bytes)
|
||||
if minor > 0:
|
||||
if add_null_padding:
|
||||
password += BNULL
|
||||
|
||||
# validate rounds
|
||||
|
||||
@@ -17,7 +17,7 @@ def varlist(name, count):
|
||||
|
||||
|
||||
def indent_block(block, padding):
|
||||
"ident block of text"
|
||||
"""ident block of text"""
|
||||
lines = block.split("\n")
|
||||
return "\n".join(
|
||||
padding + line if line else ""
|
||||
|
||||
@@ -339,7 +339,7 @@ class BlowfishEngine(object):
|
||||
# blowfish routines
|
||||
#===================================================================
|
||||
def encipher(self, l, r):
|
||||
"loop version of blowfish encipher routine"
|
||||
"""loop version of blowfish encipher routine"""
|
||||
P, S = self.P, self.S
|
||||
l ^= P[0]
|
||||
i = 1
|
||||
@@ -355,7 +355,7 @@ class BlowfishEngine(object):
|
||||
# NOTE: decipher is same as above, just with reversed(P) instead.
|
||||
|
||||
def expand(self, key_words):
|
||||
"perform stock Blowfish keyschedule setup"
|
||||
"""perform stock Blowfish keyschedule setup"""
|
||||
assert len(key_words) >= 18, "key_words must be at least as large as P"
|
||||
P, S, encipher = self.P, self.S, self.encipher
|
||||
|
||||
@@ -379,7 +379,7 @@ class BlowfishEngine(object):
|
||||
# eks-blowfish routines
|
||||
#===================================================================
|
||||
def eks_salted_expand(self, key_words, salt_words):
|
||||
"perform EKS' salted version of Blowfish keyschedule setup"
|
||||
"""perform EKS' salted version of Blowfish keyschedule setup"""
|
||||
# NOTE: this is the same as expand(), except for the addition
|
||||
# of the operations involving *salt_words*.
|
||||
|
||||
@@ -416,7 +416,7 @@ class BlowfishEngine(object):
|
||||
i += 2
|
||||
|
||||
def eks_repeated_expand(self, key_words, salt_words, rounds):
|
||||
"perform rounds stage of EKS keyschedule setup"
|
||||
"""perform rounds stage of EKS keyschedule setup"""
|
||||
expand = self.expand
|
||||
n = 0
|
||||
while n < rounds:
|
||||
@@ -425,7 +425,7 @@ class BlowfishEngine(object):
|
||||
n += 1
|
||||
|
||||
def repeat_encipher(self, l, r, count):
|
||||
"repeatedly apply encipher operation to a block"
|
||||
"""repeatedly apply encipher operation to a block"""
|
||||
encipher = self.encipher
|
||||
n = 0
|
||||
while n < count:
|
||||
|
||||
@@ -97,6 +97,7 @@ if PY3:
|
||||
return s.encode("latin-1")
|
||||
|
||||
base_string_types = (unicode, bytes)
|
||||
native_string_types = (unicode,)
|
||||
|
||||
else:
|
||||
unicode = builtins.unicode
|
||||
@@ -111,6 +112,7 @@ else:
|
||||
return s
|
||||
|
||||
base_string_types = basestring
|
||||
native_string_types = (basestring,)
|
||||
|
||||
#=============================================================================
|
||||
# unicode & bytes helpers
|
||||
@@ -253,7 +255,7 @@ else:
|
||||
if PY_MAX_25:
|
||||
_undef = object()
|
||||
def next(itr, default=_undef):
|
||||
"compat wrapper for next()"
|
||||
"""compat wrapper for next()"""
|
||||
if default is _undef:
|
||||
return itr.next()
|
||||
try:
|
||||
@@ -282,7 +284,7 @@ else:
|
||||
# introspection
|
||||
#=============================================================================
|
||||
def exc_err():
|
||||
"return current error object (to avoid try/except syntax change)"
|
||||
"""return current error object (to avoid try/except syntax change)"""
|
||||
return sys.exc_info()[1]
|
||||
|
||||
if PY3:
|
||||
@@ -291,7 +293,7 @@ else:
|
||||
method_function_attr = "im_func"
|
||||
|
||||
def get_method_function(func):
|
||||
"given (potential) method, return underlying function"
|
||||
"""given (potential) method, return underlying function"""
|
||||
return getattr(func, method_function_attr, func)
|
||||
|
||||
#=============================================================================
|
||||
@@ -366,7 +368,7 @@ else:
|
||||
from types import ModuleType
|
||||
|
||||
def _import_object(source):
|
||||
"helper to import object from module; accept format `path.to.object`"
|
||||
"""helper to import object from module; accept format `path.to.object`"""
|
||||
modname, modattr = source.rsplit(".",1)
|
||||
mod = __import__(modname, fromlist=[modattr], level=0)
|
||||
return getattr(mod, modattr)
|
||||
|
||||
@@ -81,7 +81,7 @@ _KS_MASK = 0xfcfcfcfcffffffff
|
||||
PCXROT = IE3264 = SPE = CF6464 = None
|
||||
|
||||
def _load_tables():
|
||||
"delay loading tables until they are actually needed"
|
||||
"""delay loading tables until they are actually needed"""
|
||||
global PCXROT, IE3264, SPE, CF6464
|
||||
|
||||
#---------------------------------------------------------------
|
||||
@@ -612,7 +612,7 @@ def _unpack56(value):
|
||||
_EXPAND_ITER = irange(49,-7,-7)
|
||||
|
||||
def expand_des_key(key):
|
||||
"convert DES from 7 bytes to 8 bytes (by inserting empty parity bits)"
|
||||
"""convert DES from 7 bytes to 8 bytes (by inserting empty parity bits)"""
|
||||
if isinstance(key, bytes):
|
||||
if len(key) != 7:
|
||||
raise ValueError("key must be 7 bytes in size")
|
||||
@@ -631,7 +631,7 @@ def expand_des_key(key):
|
||||
return join_byte_values(((key>>shift) & 0x7f)<<1 for shift in _EXPAND_ITER)
|
||||
|
||||
def shrink_des_key(key):
|
||||
"convert DES key from 8 bytes to 7 bytes (by discarding the parity bits)"
|
||||
"""convert DES key from 8 bytes to 7 bytes (by discarding the parity bits)"""
|
||||
if isinstance(key, bytes):
|
||||
if len(key) != 8:
|
||||
raise ValueError("key must be 8 bytes in size")
|
||||
@@ -666,7 +666,7 @@ def des_encrypt_block(key, input, salt=0, rounds=1):
|
||||
|
||||
:arg salt:
|
||||
Optional 24-bit integer used to mutate the base DES algorithm in a
|
||||
manner specific to :class:`~passlib.hash.des_crypt` and it's variants.
|
||||
manner specific to :class:`~passlib.hash.des_crypt` and its variants.
|
||||
The default value ``0`` provides the normal (unsalted) DES behavior.
|
||||
The salt functions as follows:
|
||||
if the ``i``'th bit of ``salt`` is set,
|
||||
@@ -675,7 +675,7 @@ def des_encrypt_block(key, input, salt=0, rounds=1):
|
||||
:arg rounds:
|
||||
Optional number of rounds of to apply the DES key schedule.
|
||||
the default (``rounds=1``) provides the normal DES behavior,
|
||||
but :class:`~passlib.hash.des_crypt` and it's variants use
|
||||
but :class:`~passlib.hash.des_crypt` and its variants use
|
||||
alternate rounds values.
|
||||
|
||||
:raises TypeError: if any of the provided args are of the wrong type.
|
||||
@@ -779,7 +779,7 @@ def des_encrypt_int_block(key, input, salt=0, rounds=1):
|
||||
# NOTE: generation was modified to output two elements at a time,
|
||||
# so that per-round loop could do two passes at once.
|
||||
def _iter_key_schedule(ks_odd):
|
||||
"given 64-bit key, iterates over the 8 (even,odd) key schedule pairs"
|
||||
"""given 64-bit key, iterates over the 8 (even,odd) key schedule pairs"""
|
||||
for p_even, p_odd in PCXROT:
|
||||
ks_even = _permute(ks_odd, p_even)
|
||||
ks_odd = _permute(ks_even, p_odd)
|
||||
|
||||
@@ -88,14 +88,14 @@ _UDOLLAR = u("$")
|
||||
_UZERO = u("0")
|
||||
|
||||
def validate_secret(secret):
|
||||
"ensure secret has correct type & size"
|
||||
"""ensure secret has correct type & size"""
|
||||
if not isinstance(secret, base_string_types):
|
||||
raise exc.ExpectedStringError(secret, "secret")
|
||||
if len(secret) > MAX_PASSWORD_SIZE:
|
||||
raise exc.PasswordSizeError()
|
||||
|
||||
def to_unicode_for_identify(hash):
|
||||
"convert hash to unicode for identify method"
|
||||
"""convert hash to unicode for identify method"""
|
||||
if isinstance(hash, unicode):
|
||||
return hash
|
||||
elif isinstance(hash, bytes):
|
||||
@@ -584,7 +584,7 @@ class GenericHandler(PasswordHash):
|
||||
|
||||
@staticmethod
|
||||
def _sanitize(value, char=u("*")):
|
||||
"default method to obscure sensitive fields"
|
||||
"""default method to obscure sensitive fields"""
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, bytes):
|
||||
@@ -606,7 +606,7 @@ class GenericHandler(PasswordHash):
|
||||
(with the extra keyword *checksum*).
|
||||
|
||||
this method may not work correctly for all hashes,
|
||||
and may not be available on some few. it's interface may
|
||||
and may not be available on some few. its interface may
|
||||
change in future releases, if it's kept around at all.
|
||||
|
||||
:arg hash: hash to parse
|
||||
@@ -634,7 +634,7 @@ class GenericHandler(PasswordHash):
|
||||
|
||||
@classmethod
|
||||
def bitsize(cls, **kwds):
|
||||
"[experimental method] return info about bitsizes of hash"
|
||||
"""[experimental method] return info about bitsizes of hash"""
|
||||
try:
|
||||
info = super(GenericHandler, cls).bitsize(**kwds)
|
||||
except AttributeError:
|
||||
@@ -692,7 +692,7 @@ class StaticHandler(GenericHandler):
|
||||
|
||||
@classmethod
|
||||
def _norm_hash(cls, hash):
|
||||
"helper for subclasses to normalize case if needed"
|
||||
"""helper for subclasses to normalize case if needed"""
|
||||
return hash
|
||||
|
||||
def to_string(self):
|
||||
@@ -737,7 +737,7 @@ class StaticHandler(GenericHandler):
|
||||
hash = wrapper_cls.genhash(secret, None, **context)
|
||||
warn("%r should be updated to implement StaticHandler._calc_checksum() "
|
||||
"instead of StaticHandler.genhash(), support for the latter "
|
||||
"style will be removed in Passlib 1.8" % (cls),
|
||||
"style will be removed in Passlib 1.8" % cls,
|
||||
DeprecationWarning)
|
||||
return str_to_uascii(hash)
|
||||
|
||||
@@ -920,7 +920,7 @@ class HasSalt(GenericHandler):
|
||||
|
||||
Class Attributes
|
||||
================
|
||||
In order for :meth:`!_norm_salt` to do it's job, the following
|
||||
In order for :meth:`!_norm_salt` to do its job, the following
|
||||
attributes should be provided by the handler subclass:
|
||||
|
||||
.. attribute:: min_salt_size
|
||||
@@ -986,12 +986,12 @@ class HasSalt(GenericHandler):
|
||||
|
||||
@classproperty
|
||||
def default_salt_size(cls):
|
||||
"default salt size (defaults to *max_salt_size*)"
|
||||
"""default salt size (defaults to *max_salt_size*)"""
|
||||
return cls.max_salt_size
|
||||
|
||||
@classproperty
|
||||
def default_salt_chars(cls):
|
||||
"charset used to generate new salt strings (defaults to *salt_chars*)"
|
||||
"""charset used to generate new salt strings (defaults to *salt_chars*)"""
|
||||
return cls.salt_chars
|
||||
|
||||
# private helpers for HasRawSalt, shouldn't be used by subclasses
|
||||
@@ -1082,7 +1082,7 @@ class HasSalt(GenericHandler):
|
||||
@staticmethod
|
||||
def _truncate_salt(salt, mx):
|
||||
# NOTE: some hashes (e.g. bcrypt) has structure within their
|
||||
# salt string. this provides a method to overide to perform
|
||||
# salt string. this provides a method to override to perform
|
||||
# the truncation properly
|
||||
return salt[:mx]
|
||||
|
||||
@@ -1095,7 +1095,7 @@ class HasSalt(GenericHandler):
|
||||
|
||||
@classmethod
|
||||
def bitsize(cls, salt_size=None, **kwds):
|
||||
"[experimental method] return info about bitsizes of hash"
|
||||
"""[experimental method] return info about bitsizes of hash"""
|
||||
info = super(HasSalt, cls).bitsize(**kwds)
|
||||
if salt_size is None:
|
||||
salt_size = cls.default_salt_size
|
||||
@@ -1143,7 +1143,7 @@ class HasRounds(GenericHandler):
|
||||
|
||||
Class Attributes
|
||||
================
|
||||
In order for :meth:`!_norm_rounds` to do it's job, the following
|
||||
In order for :meth:`!_norm_rounds` to do its job, the following
|
||||
attributes must be provided by the handler subclass:
|
||||
|
||||
.. attribute:: min_rounds
|
||||
@@ -1259,7 +1259,7 @@ class HasRounds(GenericHandler):
|
||||
|
||||
@classmethod
|
||||
def bitsize(cls, rounds=None, vary_rounds=.1, **kwds):
|
||||
"[experimental method] return info about bitsizes of hash"
|
||||
"""[experimental method] return info about bitsizes of hash"""
|
||||
info = super(HasRounds, cls).bitsize(**kwds)
|
||||
# NOTE: this essentially estimates how many bits of "salt"
|
||||
# can be added by varying the rounds value just a little bit.
|
||||
@@ -1448,7 +1448,10 @@ class HasManyBackends(GenericHandler):
|
||||
return name
|
||||
|
||||
def _calc_checksum_backend(self, secret):
|
||||
"stub for _calc_checksum_backend(), default backend will be selected first time stub is called"
|
||||
"""
|
||||
stub for _calc_checksum_backend(),
|
||||
the default backend will be selected the first time stub is called.
|
||||
"""
|
||||
# if we got here, no backend has been loaded; so load default backend
|
||||
assert not self._backend, "set_backend() failed to replace lazy loader"
|
||||
self.set_backend()
|
||||
@@ -1458,7 +1461,7 @@ class HasManyBackends(GenericHandler):
|
||||
return self._calc_checksum_backend(secret)
|
||||
|
||||
def _calc_checksum(self, secret):
|
||||
"wrapper for backend, for common code"""
|
||||
"""wrapper for backend, for common code"""
|
||||
return self._calc_checksum_backend(secret)
|
||||
|
||||
#=============================================================================
|
||||
@@ -1605,13 +1608,13 @@ class PrefixWrapper(object):
|
||||
return list(attrs)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
"proxy most attributes from wrapped class (e.g. rounds, salt size, etc)"
|
||||
"""proxy most attributes from wrapped class (e.g. rounds, salt size, etc)"""
|
||||
if attr in self._proxy_attrs:
|
||||
return getattr(self.wrapped, attr)
|
||||
raise AttributeError("missing attribute: %r" % (attr,))
|
||||
|
||||
def _unwrap_hash(self, hash):
|
||||
"given hash belonging to wrapper, return orig version"
|
||||
"""given hash belonging to wrapper, return orig version"""
|
||||
# NOTE: assumes hash has been validated as unicode already
|
||||
prefix = self.prefix
|
||||
if not hash.startswith(prefix):
|
||||
@@ -1620,7 +1623,7 @@ class PrefixWrapper(object):
|
||||
return self.orig_prefix + hash[len(prefix):]
|
||||
|
||||
def _wrap_hash(self, hash):
|
||||
"given orig hash; return one belonging to wrapper"
|
||||
"""given orig hash; return one belonging to wrapper"""
|
||||
# NOTE: should usually be native string.
|
||||
# (which does mean extra work under py2, but not py3)
|
||||
if isinstance(hash, bytes):
|
||||
|
||||
@@ -56,7 +56,7 @@ class md4(object):
|
||||
|
||||
.. method:: hexdigest
|
||||
|
||||
return hexdecimal version of digest
|
||||
return hexadecimal version of digest
|
||||
"""
|
||||
# FIXME: make this follow hash object PEP better.
|
||||
# FIXME: this isn't threadsafe
|
||||
@@ -146,7 +146,7 @@ class md4(object):
|
||||
]
|
||||
|
||||
def _process(self, block):
|
||||
"process 64 byte block"
|
||||
"""process 64 byte block"""
|
||||
# unpack block into 16 32-bit ints
|
||||
X = struct.unpack("<16I", block)
|
||||
|
||||
@@ -258,7 +258,7 @@ def _has_native_md4(): # pragma: no cover -- runtime detection
|
||||
if _has_native_md4():
|
||||
# overwrite md4 class w/ hashlib wrapper
|
||||
def md4(content=None):
|
||||
"wrapper for hashlib.new('md4')"
|
||||
"""wrapper for hashlib.new('md4')"""
|
||||
return hashlib.new('md4', content or b(''))
|
||||
|
||||
#=============================================================================
|
||||
|
||||
@@ -142,7 +142,7 @@ _trans_5C = join_byte_values((x ^ 0x5C) for x in irange(256))
|
||||
_trans_36 = join_byte_values((x ^ 0x36) for x in irange(256))
|
||||
|
||||
def _get_hmac_prf(digest):
|
||||
"helper to return HMAC prf for specific digest"
|
||||
"""helper to return HMAC prf for specific digest"""
|
||||
def tag_wrapper(prf):
|
||||
prf.__name__ = "hmac_" + digest
|
||||
prf.__doc__ = ("hmac_%s(key, msg) -> digest;"
|
||||
@@ -150,7 +150,7 @@ def _get_hmac_prf(digest):
|
||||
digest)
|
||||
|
||||
if _EVP and digest == "sha1":
|
||||
# use m2crypto function directly for sha1, since that's it's default digest
|
||||
# use m2crypto function directly for sha1, since that's its default digest
|
||||
try:
|
||||
result = _EVP.hmac(b('x'),b('y'))
|
||||
except ValueError: # pragma: no cover
|
||||
@@ -199,7 +199,7 @@ def _get_hmac_prf(digest):
|
||||
_prf_cache = {}
|
||||
|
||||
def _clear_prf_cache():
|
||||
"helper for unit tests"
|
||||
"""helper for unit tests"""
|
||||
_prf_cache.clear()
|
||||
|
||||
def get_prf(name):
|
||||
|
||||
Reference in New Issue
Block a user