Current File : //usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyo
�
�
5Xc@sUdZddlmZddlZddlZeje�Zddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZmZddljjZdgZd	aed
�Zed�eD��ed�eD��ed
�eD��ed�eD��gZ[d�Zd Zdej ej!ej"fd��YZ#dS(!s�passlib.handlers.sun_md5_crypt - Sun's Md5 Crypt, used on Solaris

.. warning::

    This implementation may not reproduce
    the original Solaris behavior in some border cases.
    See documentation for details.
i����(tmd5N(twarn(t
to_unicode(th64(tbyte_elem_valuetirangetut
uascii_to_strtunicodet
str_to_basciit
sun_md5_crypts�To be, or not to be,--that is the question:--
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune
Or to take arms against a sea of troubles,
And by opposing end them?--To die,--to sleep,--
No more; and by a sleep to say we end
The heartache, and the thousand natural shocks
That flesh is heir to,--'tis a consummation
Devoutly to be wish'd. To die,--to sleep;--
To sleep! perchance to dream:--ay, there's the rub;
For in that sleep of death what dreams may come,
When we have shuffled off this mortal coil,
Must give us pause: there's the respect
That makes calamity of so long life;
For who would bear the whips and scorns of time,
The oppressor's wrong, the proud man's contumely,
The pangs of despis'd love, the law's delay,
The insolence of office, and the spurns
That patient merit of the unworthy takes,
When he himself might his quietus make
With a bare bodkin? who would these fardels bear,
To grunt and sweat under a weary life,
But that the dread of something after death,--
The undiscover'd country, from whose bourn
No traveller returns,--puzzles the will,
And makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all;
And thus the native hue of resolution
Is sicklied o'er with the pale cast of thought;
And enterprises of great pith and moment,
With this regard, their currents turn awry,
And lose the name of action.--Soft you now!
The fair Ophelia!--Nymph, in thy orisons
Be all my sins remember'd.
iccs"|]}|||dfVqdS(iN((t.0ti((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys	<genexpr>Nsccs&|]}||d|dfVqdS(iiN((RR((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys	<genexpr>Osccs*|] }||d|dd@fVqdS(iiiN((RR((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys	<genexpr>Psccs.|]$}||dd@|dd@fVqdS(i	iiN((RR((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pys	<genexpr>QscCs�|dkrd}nd|}t||�j�}t\}}}}d}	x$|	|krsg|D]}
t|
�^qcj}d}||	d?d@�|	d@?d@r�|n|}
x|
D]w\}}}||�}||�}|||d?d@�||d@?d@?}|||d?d@�|d@?d@|>O}q�Wd}||	dd?d@�|	d@?d@rb|n|}x|D]w\}}}||�}||�}|||d?d@�||d@?d@?}|||d?d@�|d@?d@|>O}qoW||d?�|d@?||d?�|d@?Ad@}t|�}|r>|jt�n|jt|	�jd	��|j�}|	d7}	qPWt	j
|t�S(
s:given secret & salt, return encoded sun-md5-crypt checksumiiiiiiii@tascii(Rtdigestt
_XY_ROUNDSRt__getitem__tupdatetMAGIC_HAMLETRtencodeRtencode_transposed_bytest_chk_offsets(tsecrettroundstsalttreal_roundstresultt
X_ROUNDS_0t
X_ROUNDS_1t
Y_ROUNDS_0t
Y_ROUNDS_1troundtctrvaltxtxroundsRtiatibtatbtvtytyroundstcointh((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pytraw_sun_md5_cryptUs<	
",(,0(,2iiii
iiiiii	iii
iicBs�eZdZdZdZejZdZdZ	dZejZdZ
d	Zd
ZdZed�ed
�fZeZed�Zed��Zed��Zed�Zd�ZRS(sPThis class implements the Sun-MD5-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

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

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

    :type salt_size: int
    :param salt_size:
        If no salt is specified, this parameter can be used to specify
        the size (in characters) of the autogenerated salt.
        It currently defaults to 8.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 34000, must be between 0 and 4294963199, inclusive.

    :type bare_salt: bool
    :param bare_salt:
        Optional flag used to enable an alternate salt digest behavior
        used by some hash strings in this scheme.
        This flag can be ignored by most users.
        Defaults to ``False``.
        (see :ref:`smc-bare-salt` for details).

    :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 ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    R
RRt	bare_saltt	salt_sizeiiiЄiI��tlinears$md5$s$md5,cKs#||_tt|�j|�dS(N(R.tsuperR
t__init__(tselfR.tkwds((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyR2�s	cCstj|�}|j|j�S(N(tuhtto_unicode_for_identifyt
startswithtident_values(tclsthash((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pytidentifysc

Csnt|dd�}|jtd��r6d}d}n|jtd��r%|jtd�d�}|d	kr�tjj|d
��n|d|!}yt|�}Wn&tk
r�tjj|d��nX|t	|�kr�tjj
|��n|dkrtjj|d��n|d
}ntjj|��|jtd�|�}|d	krt||}d}t}	n�|t|�d
kr�||kr�|dtd�kr�tjj|d��n||d	!}d}t}	no|dkr.||d
td�kr.|||d
!}||d
}t}	n!|||!}||d
}t}	|d|d|d|d|	�S(NR
R:s$md5$iis$md5,rounds=t$ii����sunexpected end of roundss
bad roundssexplicit zero roundsii����stoo many '$' separatorsRRtchecksumR.(RR7RtfindR5texctMalformedHashErrortintt
ValueErrorRtZeroPaddedRoundsErrortInvalidHashErrortrfindtNonetTruetlentFalse(
R9R:Rtsalt_idxtidxtrstrtchk_idxRtchkR.((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pytfrom_stringsT	



	"
	&	
cCs�|jrtd�n	td�}|j}|dkrUtd�||j|f}ntd�|j|f}|r�|j}td�||f}nt|�S(NtR<is$md5,rounds=%d$%s%ss	$md5$%s%ss%s$%s(R.RRRR=R(R3t_withchktssRR:RN((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyt	to_stringJs!		cCsUt|t�r!|jd�}nt|jdt��}t||j|�jd�S(Nsutf-8RQR
(	t
isinstanceRRR	RSRIR-Rtdecode(R3Rtconfig((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyt_calc_checksum^s(ssaltsroundss	bare_saltR/N(t__name__t
__module__t__doc__tnametsetting_kwdsR5tHASH64_CHARStchecksum_charst
checksum_sizetdefault_salt_sizeRFt
max_salt_sizet
salt_charstdefault_roundst
min_roundst
max_roundstrounds_costRR8RIR.R2tclassmethodR;RORGRSRW(((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyR
�s&)		D(iiii
iiiiiii	iii
ii($RZthashlibRtretloggingt	getLoggerRXtlogtwarningsRt
passlib.utilsRtpasslib.utils.binaryRtpasslib.utils.compatRRRRRR	tpasslib.utils.handlerstutilsthandlersR5t__all__RtxrttupleRR-Rt	HasRoundstHasSalttGenericHandlerR
(((sB/usr/lib/python2.7/site-packages/passlib/handlers/sun_md5_crypt.pyt<module>s2.	&	O