
    =OOf                     |    d Z ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZmZ d
 ZddZd Zd Zd Zy)
    N)	ucd_3_2_0)urandom)hexlify   )SASL) RESULT_AUTH_METHOD_NOT_SUPPORTED)LDAPSASLPrepErrorLDAPPasswordIsMandatoryErrorc                 j   d}| D ]8  }t        j                  |      r|dz  }t        j                  |      r4||z  }: t        j                  d|      }|st        d      |D ]C  }t        j                  |      rt        d      t        j                  |      rt        d      t        j                  |      rt        d      t        j                  |      rt        d      t        j                  |      rt        d	      t        j                  |      rt        d
      t        j                  |      rt        d      t        j                  |      rt        d      t        j                  |      rt        d      t        j                  |      s;t        d       d}d}|D ]A  }t        j                  |      rd}nt        j                   |      rd}|s5|s8t        d       |r;t        j                  |d         s#t        j                   |d         st        d      |S )a  
    implement SASLPrep profile as per RFC4013:
    it defines the "SASLprep" profile of the "stringprep" algorithm [StringPrep].
    The profile is designed for use in Simple Authentication and Security
    Layer ([SASL]) mechanisms, such as [PLAIN], [CRAM-MD5], and
    [DIGEST-MD5].  It may be applicable where simple user names and
    passwords are used.  This profile is not intended for use in
    preparing identity strings that are not simple user names (e.g.,
    email addresses, domain names, distinguished names), or where
    identity or password strings that are not character data, or require
    different handling (e.g., case folding).
      NFKCz*SASLprep error: unable to normalize stringz1SASLprep error: non-ASCII space character presentz/SASLprep error: ASCII control character presentz3SASLprep error: non-ASCII control character presentz)SASLprep error: private character presentz0SASLprep error: non-character code point presentz,SASLprep error: surrogate code point presentz>SASLprep error: inappropriate for plain text character presentzLSASLprep error: inappropriate for canonical representation character presentzGSASLprep error: change display property or deprecated character presentz)SASLprep error: tagging character presentFTzISASLprep error: string cannot contain (R or AL) and L bidirectional charsr   zNr_and_al_cat character present, must be first and last character of the string)
stringprepin_table_c12in_table_b1	unicode32	normalizer
   in_table_c21in_table_c22in_table_c3in_table_c4in_table_c5in_table_c6in_table_c7in_table_c8in_table_c9in_table_d1in_table_d2)dataprepared_datacflag_r_and_al_cat
flag_l_cats        Y/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/protocol/sasl/sasl.py	sasl_prepr'   $   s    M ""1%S M##A&QM ''>M LMM  Q""1%#$WXX$$Q'#$UVV$$Q'#$YZZ##A&#$OPP##A&#$VWW##A&#$RSS##A&#$dee##A&#$rss##A&#$mnn##A&#$OPP=QD J q!!!$ $##A&J#$oppq !7!7a8H!IR\RhRhivwyizR{ pqq    c                     |r| s| S | st        d      t        | t              s,t        |       } t        | t              s| j	                  d      } | S )zB
    validate simple password as per RFC4013 using sasl_prep:
    zsimple password can't be emptyzutf-8)r   
isinstancebytesr'   encode)passwordaccept_emptys     r&   validate_simple_passwordr/   }   sN    
 H*+KLLh&X&(E*w/HOr(   c                    ddl m}  || j                  t        d d dd       }| j	                  | j                  d||            }| j                  j                  r| j                  }n| j                  |      d   d   }|d   t        k(  rdS dS )	Nr   bind_operationr   bindRequestr   resultTF)operation.bindr2   versionr   post_send_single_responsesendstrategysyncr4   get_responser	   )
connectioncontrolsr2   requestresponser4   s         r&   abort_sasl_negotiationr@      s    0Z//tT2tLG33JOOMSZ\d4efH""((215a8(#'GG4RURr(   c                    ddl m}  || j                  t        d d | j                  |      }| j                  | j                  d||            }| j                  j                  r| j                  }|S | j                  |      \  }}|S )Nr   r1   r3   )r5   r2   r6   r   sasl_mechanismr7   r8   r9   r:   r4   r;   )r<   r=   payloadr2   r>   r?   r4   _s           r&   send_sasl_negotiationrE      s    0Z//tT:C\C\^efG33JOOMSZ\d4efH"" M ++H5	6Mr(   c                 Z    t        t        t        |             j                  d            S )Nascii)strr   r   decode)sizes    r&   random_hex_stringrK      s!    wwt}%,,W566r(   )F)__doc__r   unicodedatar   r   osr   binasciir   r   r   core.resultsr	   core.exceptionsr
   r   r'   r/   r@   rE   rK    r(   r&   <module>rS      s=   2  .    < NVr$
S7r(   