3 L]y @sddlmZddlmZddlZddlZddlZddlZddlmZddl m Z m Z m Z m Z mZmZmZmZddd d d d d dddddg ZejdZdddZddZddZdddZddZdS))absolute_import)divisionN)_bcrypt) __author__ __copyright__ __email__ __license__ __summary__ __title____uri__ __version__r r r r rrr rgensalthashpwkdfcheckpws^\$2y\$ 2bcCs~|d krtd|dks |dkr(tdtjd}tjjdd }tjj||t|d |d d |j d d tjj |S)N2a2bz%Supported prefixes are b'2a' or b'2b'zInvalid roundszchar[]$z%2.2uascii)rr) ValueErrorosurandomrffinewlib encode_base64lenencodestring)roundsprefixsaltoutputr*3/tmp/pip-install-wfra5znf/bcrypt/bcrypt/__init__.pyr*s cCst|tjst|tjr tdd|kr0td|dd}|tjd|}}tjj dd}tj j |||t |}|dkrtd |dd tjj |d dS) Nz.Unicode-objects must be encoded before hashingz"password may not contain NUL bytesHs$2b$zchar[]rz Invalid saltr) isinstancesix text_type TypeErrorr _normalize_resubrrr r!Zbcrypt_hashpassr#r%)passwordr(Z original_salthashedretvalr*r*r+r;s cCsnt|tjst|tjr tdd|ks0d|kr8tdt||}t|t|krVdStjj ||t|dkS)Nz/Unicode-objects must be encoded before checkingr,z6password and hashed_password may not contain NUL bytesFr) r/r0r1r2rrr#rr!Ztimingsafe_bcmp)r5Zhashed_passwordretr*r*r+ras   FcCst|tjst|tjr tdt|dks8t|dkr@td|dksP|dkrXtd|dkrhtd|dkr| rtjd j|t d d t j j d |}t j j|t||t||t||}t|dkt j j||ddS) Nz.Unicode-objects must be encoded before hashingrz#password and salt must not be emptyizdesired_key_bytes must be 1-512rzrounds must be 1 or more2zrWarning: bcrypt.kdf() called with only {0} round(s). This few is not secure: the parameter is linear, like PBKDF2.) stacklevelz uint8_t[])r/r0r1r2r#rwarningswarnformat UserWarningrrr r!Z bcrypt_pbkdf_bcrypt_assertbuffer)r5r(Zdesired_key_bytesr&Zignore_few_roundskeyresr*r*r+rss& cCs|s tddS)Nzbcrypt assertion failed) SystemError)okr*r*r+r@sr@)rr)F) __future__rrrrer<r0r __about__rrrr r r r r __all__compiler3rrrrr@r*r*r*r+s   (    & "