a fWc#@sdZddlmZmZddlmZddlZddlZee Z ddl m Z m Z ddlmZmZmZmZmZddlmZddlmmZdd gZdd d ZdZGdddejejZGdddej ej!Z"dS)z3passlib.handlers.oracle - Oracle DB Password Hashes)hexlify unhexlify)sha1N) to_unicode xor_bytes)irangeu uascii_to_strunicode str_to_uascii)des_encrypt_blockZ oracle10gZ oracle11gcCsT||t| d7}|}tdt|dD]$}t||||d}t||}q*|S)aperforms des-cbc encryption, returns only last block. this performs a specific DES-CBC encryption implementation as needed by the Oracle10 hash. it probably won't be useful for other purposes as-is. input value is null-padded to multiple of 8 bytes. :arg key: des key as bytes :arg value: value to encrypt, as bytes. :param iv: optional IV :param pad: optional pad byte :returns: last block of DES-CBC encryption of all ``value``'s byte blocks. r)lenrrr )keyvalueZivZpadhashoffsetchunkr;/usr/lib/python3.9/site-packages/passlib/handlers/oracle.pydes_cbc_encrypts  rs#Egc@s2eZdZdZdZejZdZe ddZ ddZ dS)oracle10aThis class implements the password hash used by Oracle up to version 10g, and follows the :ref:`password-hash-api`. It does a single round of hashing, and relies on the username as the salt. The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the following additional contextual keywords: :type user: str :param user: name of oracle user account this password is associated with. cCs|S)N)upper)clsrrrr _norm_hashIszoracle10._norm_hashcCs\t|tr|d}t|jddd}||d}tt|}t||}t |dS)Nutf-8user)Zparamz utf-16-beascii) isinstancebytesdecoderrrencoderORACLE10_MAGICr)selfsecretrinputrrrr_calc_checksumMs    zoracle10._calc_checksumN) __name__ __module__ __qualname____doc__nameuhZ HEX_CHARSchecksum_chars checksum_size classmethodrr)rrrrr4s  rc@s^eZdZdZdZdZdZejZ dZ Z ejZ e ede jZeddZdd Zd d Zd S) oracle11aEThis class implements the Oracle11g password hash, and follows the :ref:`password-hash-api`. It supports a fixed-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 20 hexadecimal characters. :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 )salt(z/^S:(?P[0-9a-f]{40})(?P[0-9a-f]{20})$cCsHt|dd}|j|}|s(tj||dd\}}|||dS)Nr rr4chk)r4checksum)r _hash_regexmatchr/excZInvalidHashErrorgroupr)rrmr4r7rrr from_strings    zoracle11.from_stringcCs(|j}td||jf}t|S)NzS:%s%s)r8rrr4r )r&r7rrrr to_stringszoracle11.to_stringcCs<t|tr|d}t|t|jd}t|S)Nrr ) r!r r$rrr4 hexdigestr r)r&r'r7rrrr)s  zoracle11._calc_checksumN)r*r+r,r-r.Z setting_kwdsr1r/ZUPPER_HEX_CHARSr0Z min_salt_sizeZ max_salt_sizeZ salt_charsrecompilerIr9r2r>r?r)rrrrr3hs r3)r r)#r-ZbinasciirrZhashlibrrAZloggingZ getLoggerr*logZ passlib.utilsrrZpasslib.utils.compatrrr r r Zpasslib.crypto.desr Zpasslib.utils.handlersZutilshandlersr/__all__rr%ZHasUserContextZ StaticHandlerrZHasSaltZGenericHandlerr3rrrrs   4