o
    _6d#                     @   s   d Z ddlmZmZ ddlmZ ddlZddlZe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  mZ dd	gZdddZdZG dd dejejZG d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_blockZ	oracle10gZ	oracle11g               c                 C   sT   ||t | d  7 }|}tdt |dD ]}t||||d  }t| |}q|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valueZivpadhashoffsetchunk r   nC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\passlib/handlers/oracle.pydes_cbc_encrypt   s   r   s   #Egc                   @   s2   e Zd ZdZd ZejZdZe	dd Z
d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                 C   s   |  S )N)upper)clsr   r   r   r   
_norm_hashI   s   zoracle10._norm_hashc                 C   s\   t |tr
|d}t| jddd}||  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   r   r   r   _calc_checksumM   s   



zoracle10._calc_checksumN)__name__
__module____qualname____doc__nameuhZ	HEX_CHARSchecksum_charschecksum_sizeclassmethodr   r+   r   r   r   r   r   4   s    
r   c                   @   s^   e Zd ZdZd ZdZdZejZ	d Z
ZejZeedejZedd Zdd	 Zd
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                 C   sH   t |dd}| j|}|stj| |dd\}}| || dS )Nr"   r   r6   chk)r6   checksum)r   _hash_regexmatchr1   excZInvalidHashErrorgroupr   )r   r   mr6   r9   r   r   r   from_string   s   zoracle11.from_stringc                 C   s(   | j }td| | j f }t|S )NzS:%s%s)r:   r   r   r6   r	   )r(   r9   r   r   r   r   	to_string   s   zoracle11.to_stringc                 C   s<   t |tr
|d}t|t| jd  }t| S )Nr   r"   )	r#   r
   r&   r   r   r6   	hexdigestr   r   )r(   r)   r9   r   r   r   r+      s   

zoracle11._calc_checksumN)r,   r-   r.   r/   r0   Zsetting_kwdsr3   r1   ZUPPER_HEX_CHARSr2   Zmin_salt_sizeZmax_salt_sizeZ
salt_charsrecompiler   Ir;   r4   r@   rA   r+   r   r   r   r   r5   h   s    
r5   )r   r   )#r/   binasciir   r   hashlibr   rC   logging	getLoggerr,   logZpasslib.utilsr   r   Zpasslib.utils.compatr   r   r	   r
   r   Zpasslib.crypto.desr   Zpasslib.utils.handlersutilshandlersr1   __all__r   r'   ZHasUserContextZStaticHandlerr   ZHasSaltZGenericHandlerr5   r   r   r   r   <module>   s     
4