Current File : //usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyc
�
�
5Xc@sdZddlmZmZddlmZddlZddlZeje	�Z
ddlmZm
Z
ddlmZmZmZmZmZddlmZddljjZdd	gZdd
d�Zd
Zdejejfd��YZdej ej!fd��YZ"dS(s3passlib.handlers.oracle - Oracle DB Password Hashesi����(thexlifyt	unhexlify(tsha1N(t
to_unicodet	xor_bytes(tirangetut
uascii_to_strtunicodet
str_to_uascii(tdes_encrypt_blockt	oracle10gt	oracle11gticCso||t|�d7}|}xItdt|�d�D]/}t||||d!�}t||�}q8W|S(s�performs 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.
    ii(tlenRRR
(tkeytvaluetivtpadthashtoffsettchunk((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pytdes_cbc_encryptss#Eg����toracle10cBs;eZdZdZejZdZed��Z	d�Z
RS(s�This 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.
    RicCs
|j�S(N(tupper(tclsR((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyt
_norm_hashIscCs�t|t�r!|jd�}nt|jddd�}||j�jd�}tt|�}t||�}t	|�jd�j�S(Nsutf-8tparamtusers	utf-16-betascii(
t
isinstancetbytestdecodeRRRtencodeRtORACLE10_MAGICR(tselftsecretRtinputR((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyt_calc_checksumMs(t__name__t
__module__t__doc__tnametuht	HEX_CHARStchecksum_charst
checksum_sizetclassmethodRR&(((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyR4s
	toracle11cBsxeZdZdZd	ZdZejZdZ	Z
ejZej
ed�ej�Zed��Zd�Zd�ZRS(
sEThis 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
    R0tsalti(is/^S:(?P<chk>[0-9a-f]{40})(?P<salt>[0-9a-f]{20})$cCspt|dd�}|jj|�}|s?tjj|��n|jdd�\}}|d|d|j��S(NRRR1tchktchecksum(Rt_hash_regextmatchR+texctInvalidHashErrortgroupR(RRtmR1R2((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pytfrom_string�scCs8|j}td�|j�|jj�f}t|�S(NsS:%s%s(R3RRR1R(R#R2R((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyt	to_string�s	%cCsYt|t�r!|jd�}nt|t|jjd���j�}t|�j�S(Nsutf-8R(	RRR!RRR1t	hexdigestR	R(R#R$R2((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyR&�s((ssalt(R'R(R)R*tsetting_kwdsR.R+tUPPER_HEX_CHARSR-t
min_salt_sizet
max_salt_sizet
salt_charstretcompileRtIR4R/R:R;R&(((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyR0hs	
			t(#R)tbinasciiRRthashlibRRBtloggingt	getLoggerR'tlogt
passlib.utilsRRtpasslib.utils.compatRRRRR	tpasslib.crypto.desR
tpasslib.utils.handlerstutilsthandlersR+t__all__RR"tHasUserContextt
StaticHandlerRtHasSalttGenericHandlerR0(((s;/usr/lib/python2.7/site-packages/passlib/handlers/oracle.pyt<module>s(	4