Current File : //usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyo
�
�;Xc@sOdZddlmZddlZeje�ZddlmZm	Z	m
Z
ddlmZddl
mZmZddljjZddgZd	Zd
ZdZd!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5fZd6Zed�Zdejejfd��YZdejefd��YZ defd ��YZ!dS(7s0passlib.handlers.md5_crypt - md5-crypt algorithmi����(tmd5N(t
safe_cryptt
test_cryptt
repeat_string(th64(tunicodetut	md5_cryptt
apr_md5_cryptts$1$s$apr1$iiiiiiiii
iiiii	i
icCs(t|t�r!|jd�}nt|krBtjjt��nt|�}|jd�}|rlt	}nt
}t|||�j�}t|||�}|j
}|t||��|}|d }	x.|r�||d@r�tn|	�|dL}q�W|j�}
||}||}|||||||||g}
gtD] \}}|
||
|f^qH}|
}d}xQ|r�x:|D]2\}}t|t||�j��j�}q�W|d8}q}Wx>|d D]2\}}t|t||�j��j�}q�Wtj|t�jd�S(s�perform raw md5-crypt calculation

    this function provides a pure-python implementation of the internals
    for the MD5-Crypt algorithms; it doesn't handle any of the
    parsing/validation of the hash strings themselves.

    :arg pwd: password chars/bytes to hash
    :arg salt: salt chars to use
    :arg use_apr: use apache variant

    :returns:
        encoded checksum chars
    sutf-8tasciiiii(t
isinstanceRtencodet_BNULLtuhtexctNullPasswordErrorRtlent
_APR_MAGICt
_MD5_MAGICRtdigesttupdateRt_c_digest_offsetsRtencode_transposed_bytest_transpose_maptdecode(tpwdtsalttuse_aprtpwd_lentmagictdbta_ctxta_ctx_updatetitevenchartdatpwd_pwdtpwd_salttpermsteventoddtdatatdctblocks((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_raw_md5_crypt,s@		
	.

$-	**t_MD5_CommoncBsJeZdZdZdZejZdZejZ	e
d��Zd�ZRS(s+common code for md5_crypt and apr_md5_cryptRt	salt_sizeiicCs4tj||jd|�\}}|d|d|�S(NthandlerRtchecksum(Rt	parse_mc2tident(tclsthashRtchk((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pytfrom_string�s!cCstj|j|j|j�S(N(Rt
render_mc2R3RR1(tself((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt	to_string�s(ssaltR/(
t__name__t
__module__t__doc__tsetting_kwdst
checksum_sizeRtHASH64_CHARStchecksum_charst
max_salt_sizet
salt_charstclassmethodR7R:(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyR.�s		cBsVeZdZdZed�Zd	Zed��Zd�Z	ed��Z
d�ZRS(
s�This class implements the MD5-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 0-8 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type salt_size: int
    :param salt_size:
        Optional number of characters to use when autogenerating new salts.
        Defaults to 8, but can be any value between 0 and 8.
        (This is mainly needed when generating Cisco-compatible hashes,
        which require ``salt_size=4``).

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include
        ``salt`` strings that are too long.

        .. versionadded:: 1.6
    Rs$1$tos_crypttbuiltincCs+tdd�r#|j|j�tStSdS(Nttests$1$test$pi/xDtU5WFVRqYS6BMU8X/(Rt_set_calc_checksum_backendt_calc_checksum_os_crypttTruetFalse(R4((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_load_backend_os_cryptscCs>|j|j}t||�}|r-|dS|j|�SdS(Ni��(R3RRt_calc_checksum_builtin(R9tsecrettconfigR5((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyRIs
cCs|j|j�tS(N(RHRMRJ(R4((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_load_backend_builtin%scCst||j�S(N(R-R(R9RN((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyRM*s(RERF(R;R<R=tnameRR3tbackendsRDRLRIRPRM(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyR�s	cBs)eZdZdZed�Zd�ZRS(spThis class implements the Apr-MD5-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 0-8 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include
        ``salt`` strings that are too long.

        .. versionadded:: 1.6
    Rs$apr1$cCst||jdt�S(NR(R-RRJ(R9RN((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt_calc_checksumQs(R;R<R=RQRR3RS(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyR1s(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(iiii
iiiiiii	iii
ii("R=thashlibRtloggingt	getLoggerR;tlogt
passlib.utilsRRRtpasslib.utils.binaryRtpasslib.utils.compatRRtpasslib.utils.handlerstutilsthandlersRt__all__R
RRRRRKR-tHasSalttGenericHandlerR.tHasManyBackendsRR(((s>/usr/lib/python2.7/site-packages/passlib/handlers/md5_crypt.pyt<module>s(	� Q