
    g#                     8   S r SSKJrJr  SSKJr  SSKrSSKr\R                  " \	5      r
SSKJrJr  SSKJrJrJrJrJr  SSKJr  SSKJs  Jr  SS	/rSS
 jrSr " S S\R:                  \R<                  5      r " S S\R@                  \RB                  5      r"g)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                     X[        U5      * S-  -  -  nUn[        S[        U5      S5       H  n[        XAXUS-    5      n[        X5      nM      U$ )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          P/home/matz/Project1/venv/lib/python3.13/site-packages/passlib/handlers/oracle.pydes_cbc_encryptr      s[      
SZK!O$$ED3u:a($fAX 67 , ) K    s   #Egc                   N    \ rS rSrSrS r\R                  rSr	\
S 5       rS rSrg)oracle104   a  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                 "    UR                  5       $ )N)upper)clsr   s     r   
_norm_hashoracle10._norm_hashI   s    zz|r   c                 @   [        U[        5      (       a  UR                  S5      n[        U R                  SSS9nX!-   R                  5       R                  S5      n[        [        U5      n[        XC5      n[        U5      R                  S5      R                  5       $ )Nutf-8user)paramz	utf-16-beascii)

isinstancebytesdecoder   r(   r"   encoder   ORACLE10_MAGICr   )selfsecretr(   inputr   s        r   _calc_checksumoracle10._calc_checksumM   s     fe$$]]7+F$))WF;##%,,[9~u5t+t}##G,2244r    N)__name__
__module____qualname____firstlineno____doc__nameuh	HEX_CHARSchecksum_charschecksum_sizeclassmethodr$   r3   __static_attributes__r5   r   r   r   r   4   s5    	 D\\NM
  5r   r   c                       \ rS rSrSrS rSrSr\R                  r
S=rr\R                  r\R                  " \" S5      \R"                  5      r\S 5       rS rS	 rS
rg)oracle11h   a  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                     [        USS5      nU R                  R                  U5      nU(       d  [        R                  R                  U 5      eUR                  SS5      u  p4U " X4R                  5       S9$ )Nr*   r   rE   chk)rE   checksum)r   _hash_regexmatchr<   excInvalidHashErrorgroupr"   )r#   r   mrE   rI   s        r   from_stringoracle11.from_string   s_    $0OO!!$'&&))#..GGFE*	yy{33r   c                     U R                   n[        S5      UR                  5       U R                  R                  5       4-  n[	        U5      $ )NzS:%s%s)rJ   r	   r"   rE   r
   )r0   rI   r   s      r   	to_stringoracle11.to_string   s:    mm{ciik499??+<==T""r   c                     [        U[        5      (       a  UR                  S5      n[        U[	        U R
                  R                  S5      5      -   5      R                  5       n[        U5      R                  5       $ )Nr'   r*   )	r+   r   r.   r   r   rE   	hexdigestr   r"   )r0   r1   rI   s      r   r3   oracle11._calc_checksum   s]    fg&&]]7+F6Idii&6&6w&?@@AKKMS!''))r   r5   N)r6   r7   r8   r9   r:   r;   setting_kwdsr?   r<   UPPER_HEX_CHARSr>   min_salt_sizemax_salt_size
salt_charsrecompiler	   IrK   r@   rQ   rT   r3   rA   r5   r   r   rC   rC   h   su    4 DLM''N %'&MM##J **QPQSUSWSWXK4 4#
*r   rC   )s               )#r:   binasciir   r   hashlibr   r^   logging	getLoggerr6   logpasslib.utilsr   r   passlib.utils.compatr   r	   r
   r   r   passlib.crypto.desr   passlib.utils.handlersutilshandlersr<   __all__r   r/   HasUserContextStaticHandlerr   HasSaltGenericHandlerrC   r5   r   r   <module>rr      s    9
 (  	 g''1 0G G 0 # # 0 5+5r  ""2"2 +5h<*rzz2,, <*r   