a ܅gk@sdZddlZz ddlZWn&ey>dZdZddlmZ Yn0ej Z e ej Zddl Ze seddedDZeddedDZdZGdd d Zdd d Zd dZdS)zqHMAC (Keyed-Hashing for Message Authentication) module. Implements the HMAC algorithm as described by RFC 2104. N)_compare_digestccs|]}|dAVqdS)\N.0xrr/usr/lib64/python3.9/hmac.py r ccs|]}|dAVqdS)6Nrrrrrr r c@sfeZdZdZdZdZdddZdd Zd d Ze d d Z ddZ ddZ ddZ ddZddZdS)HMACz~RFC 2104 HMAC class. Also complies with RFC 4231. This supports the API for Cryptographic Hash Functions (PEP 247). @)_hmac_inner_outer block_size digest_sizeNcCst|ttfs tdt|j|s,tdtsFtrt|tt frz| |||Wqtj ytrr| |||Yq0n| |||dS)a?Create a new HMAC object. key: bytes or buffer, key for the keyed hash object. msg: bytes or buffer, Initial input for the hash or None. digestmod: A hash name suitable for hashlib.new(). *OR* A hashlib constructor returning a new hash object. *OR* A module supporting PEP 247. Required as of 3.8, despite its position after the optional msg argument. Passing it as a keyword argument is recommended, though not required for legacy API reasons. z,key: expected bytes or bytearray, but got %rz'Missing required parameter 'digestmod'.N) isinstancebytes bytearray TypeErrortype__name__ _hashopenssl get_fips_modestr _functype _init_hmacUnsupportedDigestmodError _init_oldselfkeymsg digestmodrrr__init__'s z HMAC.__init__cCs*tj|||d|_|jj|_|jj|_dS)Nr&)rhmac_newrrrr"rrrrDs zHMAC._init_hmaccs(tr|||Str$}n(ttr>d fdd }nd fdd }d|_||_||_|jj |_ t |jdr|jj }|dkrt d||jftd|j}nt d |jtd|j}t||kr||}||_ ||d }|j|t|j|t|dur$||dS) Nr cs t|SN_hashlibnewdr(rrPr z HMAC._init_old..cs |Sr*r-r.r(rrr0Rr rz:block_size of %d seems too small; using our default of %d.z)r#r%instrrrr>zs z HMAC.updatecCsX|j|j}|j|_|jr6|j|_d|_|_nd|_|j|_|j|_|S)zyReturn a separate copy of this hashing object. An update to this copy won't affect the original object. N) __class____new__rrcopyrr)r#otherrrrrGs   z HMAC.copycCs.|jr |jS|j}||j|SdS)zwReturn a hash object for the current state. To be used only internally with digest() and hexdigest(). N)rrrGr>rr<r#hrrr_currents  z HMAC._currentcCs|}|S)zReturn the hash value of this hashing object. This returns the hmac value as bytes. The object is not altered in any way by this function; you can continue updating the object after calling this function. )rKr<rIrrrr<sz HMAC.digestcCs|}|S)zKLike digest(), but returns a string of hexadecimal digits instead. )rK hexdigestrIrrrrLszHMAC.hexdigest)Nr)r __module__ __qualname____doc__r9 __slots__r'rr!propertyrCr>rGrKr<rLrrrrr s *   r rcCs t|||S)aCreate a new hashing object and return it. key: bytes or buffer, The starting key for the hash. msg: bytes or buffer, Initial input for the hash, or None. digestmod: A hash name suitable for hashlib.new(). *OR* A hashlib constructor returning a new hash object. *OR* A module supporting PEP 247. Required as of 3.8, despite its position after the optional msg argument. Passing it as a keyword argument is recommended, though not required for legacy API reasons. You can now feed arbitrary bytes into the object using its update() method, and can ask for the hash value at any time by calling its digest() or hexdigest() methods. )r )r$r%r&rrrr-sr-cstdur.cs |Sr*r1r.rRrrr0r rrr4)r )r )rrrr hmac_digestr r5getattrr;r<r>r?rAr@)r$r%r<rBinnerZouterr9rrRrr<s*      r<)Nr)rOwarningsr7r,r ImportErrorr _operatorrcompare_digestropenssl_sha256hashlibrrranger@rArr r-r<rrrrs$