a fWcm6@sdZddlmZddlZddlZeeZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZddlmmZdgZd aed Zed d eDed d eDedd eDedd eDgZ[ddZdZGdddej ej!ej"Z#dS)zpasslib.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. )md5N)warn) to_unicode)h64)byte_elem_valueirangeu uascii_to_strunicode str_to_bascii sun_md5_cryptsTo 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. ccs|]}|||dfVqdS)N.0irrB/usr/lib/python3.9/site-packages/passlib/handlers/sun_md5_crypt.py Nrccs |]}||d|dfVqdS)NrrrrrrOrccs$|]}||d|dd@fVqdS) NrrrrrrPrccs(|] }||dd@|dd@fVqdS) r NrrrrrrQrcCst|tsJt|tsJ|dkr(d}d|}t||}t|dksPJt\}}}}d} | |kr dd|Dj} d} | | d?d@| d@?d @r|n|} | D]b\} }}| |}| |}| ||d ?d@||d@?d @?}| | |d?d@|d@?d @| >O} qd}| | d d?d@| d@?d @r4|n|}|D]d\} }}| |}| |}| ||d ?d@||d@?d @?}|| |d?d@|d@?d @| >O}q<| | d?| d@?| |d?|d@?Ad @}t|}|r|t|t |  d |}| d 7} q`t |t S) z:given secret & salt, return encoded sun-md5-crypt checksumricSsg|] }t|qSr)r)rcrrr rz%raw_sun_md5_crypt..rrr r@ascii) isinstancebytesrdigestlen _XY_ROUNDS __getitem__update MAGIC_HAMLETr encoderZencode_transposed_bytes _chk_offsets)secretroundssaltZ real_roundsresultZ X_ROUNDS_0Z X_ROUNDS_1Z Y_ROUNDS_0Z Y_ROUNDS_1roundZrvalxZxroundsriaZibabvyZyroundsZcoinhrrrraw_sun_md5_cryptUsB  $$&*$(,  r9)rr r rrrrrr rrcseZdZdZdZdZejZdZ dZ dZ ejZ dZ dZdZd Zed ed fZd Zdfd d ZeddZeddZdddZddZZS)r aPThis 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/r. bare_saltZ salt_sizerNiЄrloZlinear$md5$z$md5,Fc s ||_tt|jfi|dSN)r?superr __init__)selfr?kwds __class__rrrDszsun_md5_crypt.__init__cCst|}||jSrB)uhZto_unicode_for_identify startswith ident_values)clshashrrridentifys zsun_md5_crypt.identifyc Cst|dd}|tdr$d}d}n|tdr|tdd}|d krXtj|d |d|}z t|}Wn tytj|d Yn0|t |krtj ||dkrtj|d |d }n tj || td|}|d kr||d}d}d} n|t |d krX||krB|dtdkrBtj|d||d }d}d} nf|dkr||d tdkr|||d }||d d}d} n |||}||d d}d} ||||| dS)Nr"rMrArr z $md5,rounds=$rzunexpected end of roundsz bad roundszexplicit zero roundsrTztoo many '$' separatorsF)r.r/checksumr?)rrJrfindrIexcZMalformedHashErrorint ValueErrorr ZZeroPaddedRoundsErrorZInvalidHashErrorrfindr&) rLrMr.Zsalt_idxidxZrstrZchk_idxr/chkr?rrr from_stringsV             zsun_md5_crypt.from_stringTcCsn|jrtdntd}|j}|dkr:td||j|f}ntd|j|f}|rf|j}td||f}t|S)NrOrz$md5,rounds=%d$%s%sz $md5$%s%sz%s$%s)r?rr.r/rRr )rE_withchkssr.rMrYrrr to_stringJszsun_md5_crypt.to_stringcCs8t|tr|d}t|jdd}t||j|dS)Nzutf-8F)r\r")r#r r+r r^r9r.decode)rEr-Zconfigrrr_calc_checksum^s  zsun_md5_crypt._calc_checksum)F)T)__name__ __module__ __qualname____doc__nameZ setting_kwdsrIZ HASH64_CHARSZchecksum_charsZ checksum_sizeZdefault_salt_sizeZ max_salt_sizeZ salt_charsZdefault_roundsZ min_roundsZ max_roundsZ rounds_costrrKr?rD classmethodrNrZr^r` __classcell__rrrGrr s*,  C )$rdZhashlibrreZloggingZ getLoggerralogwarningsrZ passlib.utilsrZpasslib.utils.binaryrZpasslib.utils.compatrrrr r r Zpasslib.utils.handlersZutilshandlersrI__all__r*Zxrtupler'r9r,Z HasRoundsZHasSaltZGenericHandlerr rrrrs,      'N