
    XR_#                        d Z ddlmZmZ ddlmZ ddlZddlZ ej        e	          Z
ddlmZmZ ddlmZmZmZmZmZ ddlmZ ddlmc mZ dd	gZddZdZ G d dej        ej                  Z G d dej         ej!                  Z"dS )z3passlib.handlers.oracle - Oracle DB Password Hashes    )hexlify	unhexlify)sha1N)
to_unicode	xor_bytes)irangeuuascii_to_strunicodestr_to_uascii)des_encrypt_block	oracle10g	oracle11g               c                     ||t          |           dz  z  z  }|}t          dt          |          d          D ]-}t          ||||dz                      }t          | |          }.|S )a  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.
       r   )lenr   r   r   )keyvalueivpadhashoffsetchunks          9/usr/lib/python3/dist-packages/passlib/handlers/oracle.pydes_cbc_encryptr      sw      
SSZZK!O$$ED3u::a(( - -$fVAXo 677 e,,K    s   #Egc                   D    e Zd ZdZd Zej        ZdZe	d             Z
d ZdS )oracle10a  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.
       c                 *    |                                 S )N)upper)clsr   s     r   
_norm_hashzoracle10._norm_hashI   s    zz||r   c                    t          |t                    r|                    d          }t          | j        dd          }||z                                                       d          }t          t          |          }t          ||          }t          |                              d                                          S )Nutf-8user)paramz	utf-16-beascii)

isinstancebytesdecoder   r(   r#   encoder   ORACLE10_MAGICr   )selfsecretr(   inputr   s        r   _calc_checksumzoracle10._calc_checksumM   s     fe$$ 	,]]7++F$)WF;;;f##%%,,[99~u55tU++t}}##G,,22444r   N)__name__
__module____qualname____doc__nameuh	HEX_CHARSchecksum_charschecksum_sizeclassmethodr%   r3    r   r   r    r    4   s[        	 	 D\NM
   [5 5 5 5 5r   r    c                       e Zd ZdZd ZdZdZej        Z	dxZ
Zej        Z ej         ed          ej                  Zed             Zd Zd Zd	S )
oracle11aE  This 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<chk>[0-9a-f]{40})(?P<salt>[0-9a-f]{20})$c                 
   t          |dd          }| j                            |          }|st          j                            |           |                    dd          \  }} | ||                                          S )Nr*   r   rA   chk)rA   checksum)r   _hash_regexmatchr9   excInvalidHashErrorgroupr#   )r$   r   mrA   rE   s        r   from_stringzoracle11.from_string   sz    $00O!!$'' 	/&))#...GGFE**	cssyy{{3333r   c                     | j         }t          d          |                                | j                                        fz  }t	          |          S )NzS:%s%s)rF   r	   r#   rA   r
   )r0   rE   r   s      r   	to_stringzoracle11.to_string   s@    m{{ciikk49??+<+<==T"""r   c                 *   t          |t                    r|                    d          }t          |t	          | j                            d                    z                                             }t          |                                          S )Nr'   r*   )	r+   r   r.   r   r   rA   	hexdigestr   r#   )r0   r1   rE   s      r   r3   zoracle11._calc_checksum   su    fg&& 	,]]7++F6Idi&6&6w&?&?@@@AAKKMMS!!'')))r   N)r4   r5   r6   r7   r8   setting_kwdsr<   r9   UPPER_HEX_CHARSr;   min_salt_sizemax_salt_size
salt_charsrecompiler	   IrG   r=   rM   rO   r3   r>   r   r   r@   r@   h   s         4 DLM'N %'&MM#J "*QQPQQSUSWXXK4 4 [4# # #
* * * * *r   r@   )r   r   )#r7   binasciir   r   hashlibr   rW   logging	getLoggerr4   logpasslib.utilsr   r   passlib.utils.compatr   r	   r
   r   r   passlib.crypto.desr   passlib.utils.handlersutilshandlersr9   __all__r   r/   HasUserContextStaticHandlerr    HasSaltGenericHandlerr@   r>   r   r   <module>rj      s   9 9
 ( ' ' ' ' ' ' '       				 'g'11 0 / / / / / / /G G G G G G G G G G G G G G 0 0 0 0 0 0 # # # # # # # # #    0 5+5 +5 +5 +5 +5r ""2 +5 +5 +5h<* <* <* <* <*rz2, <* <* <* <* <*r   