
    ;OOf#                     6   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jB                        Z"y)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	oracle11gc                     ||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          X/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/passlib/handlers/oracle.pydes_cbc_encryptr      sh      
SSZK!O$$ED3u:a( -$fVAX 67 e,- K    s   #Egc                   F    e Zd ZdZd Zej                  ZdZe	d        Z
d Zy)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                 "    |j                         S )N)upper)clsr   s     r   
_norm_hashzoracle10._norm_hashI   s    zz|r   c                 @   t        |t              r|j                  d      }t        | j                  dd      }||z   j                         j                  d      }t        t        |      }t        ||      }t        |      j                  d      j                         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~u5tU+t}##G,2244r   N)__name__
__module____qualname____doc__nameuh	HEX_CHARSchecksum_charschecksum_sizeclassmethodr#   r1    r   r   r   r   4   s5    	 D\\NM
  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y	)
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                  j                  |      }|st        j                  j                  |       |j                  dd      \  }} | ||j                               S )Nr(   r   r?   chk)r?   checksum)r   _hash_regexmatchr7   excInvalidHashErrorgroupr!   )r"   r   mr?   rC   s        r   from_stringzoracle11.from_string   sc    $0OO!!$'&&))#..GGFE*	csyy{33r   c                     | j                   }t        d      |j                         | j                  j                         fz  }t	        |      S )NzS:%s%s)rD   r	   r!   r?   r
   )r.   rC   r   s      r   	to_stringzoracle11.to_string   s:    mm{ciik499??+<==T""r   c                     t        |t              r|j                  d      }t        |t	        | j
                  j                  d            z         j                         }t        |      j                         S )Nr%   r(   )	r)   r   r,   r   r   r?   	hexdigestr   r!   )r.   r/   rC   s      r   r1   zoracle11._calc_checksum   sZ    fg&]]7+F6Idii&6&6w&?@@AKKMS!''))r   N)r2   r3   r4   r5   r6   setting_kwdsr:   r7   UPPER_HEX_CHARSr9   min_salt_sizemax_salt_size
salt_charsrecompiler	   IrE   r;   rK   rM   r1   r<   r   r   r>   r>   h   sw    4 DLM''N %'&MM##J "**QPQSUSWSWXK4 4#
*r   r>   )s               )#r5   binasciir   r   hashlibr   rU   logging	getLoggerr2   logpasslib.utilsr   r   passlib.utils.compatr   r	   r
   r   r   passlib.crypto.desr   passlib.utils.handlersutilshandlersr7   __all__r   r-   HasUserContextStaticHandlerr   HasSaltGenericHandlerr>   r<   r   r   <module>ri      s    9
 (  	 'g''1 0G G 0 # # 0 5+5r  ""2"2 +5h<*rzz2,, <*r   