
    mgX                         d Z ddlZddlZddlmZmZmZ ddlmZ  G d de	      Z
deddfd	Zded
edeeegef      ded   deeegef      dedefdZdedefdZdedefdZy)zSASLprep implementation

   This module implements the stringprep algorithm defined in RFC 3454
   and the SASLprep profile of stringprep defined in RFC 4013. This
   profile is used to normalize usernames and passwords sent in the
   SSH protocol.

    N)CallableOptionalSequence)Literalc                       e Zd ZdZy)SASLPrepErrorz!Invalid data provided to saslprepN)__name__
__module____qualname____doc__     1lib/python3.12/site-packages/asyncssh/saslprep.pyr   r   (   s    +r   r   sreturnc                    d}d}| D ]6  }|st        j                  |      rd}|rt        j                  |      s5d}8 |r|rt        d      |r<t        j                  | d         rt        j                  | d         st        d      yy)z@Enforce bidirectional character check from RFC 3454 (stringprep)FTz*Both RandALCat and LCat characters presentr   z-RandALCat character not at both start and endN)
stringprepin_table_d1in_table_d2r   )r   r_and_al_catl_catcs       r   _check_bidir   ,   s     LE
 6 6q 9L//2E  HIIZ33AaD9'33AbE:KLL ; r   check_unassignedmappingnormalization)NFCNFDNFKCNFKD
prohibitedbidic                    |r*| D ]%  }t        j                  |      st        d|z         |r ||       } |rt        j                  ||       } |r$| D ]  }|D ]  } ||      st        d|z         ! |rt        |        | S )z5Implement a stringprep profile as defined in RFC 3454zUnassigned character: %rzProhibited character: %r)r   in_table_a1r   unicodedata	normalizer   )r   r   r   r   r"   r#   r   lookups           r   _stringprepr)   A   s     A%%a(#$>$BCC  AJ!!-3A$!9'(BQ(FGG % 
 AHr   c                     g }| D ]P  }t        j                  |      r|j                  d       *t        j                  |      r@|j                  |       R dj	                  |      S )z<Map stringprep table B.1 to nothing and C.1.2 to ASCII space  )r   in_table_c12appendin_table_b1join)r   rr   s      r   _map_saslprepr2   _   sU     	A""1%HHSM''*HHQK	  771:r   c           	      <   t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  f	}t        | dt        d|d      S )z.Implement SASLprep profile defined in RFC 4013Tr    )r   r-   in_table_c21_c22in_table_c3in_table_c4in_table_c5in_table_c6in_table_c7in_table_c8in_table_c9r)   r2   )r   r"   s     r   saslprepr<   m   so     )):+F+F((**@*@((**@*@((**@*@((	*J q$vz4HHr   )r   r   r&   typingr   r   r   typing_extensionsr   
ValueErrorr   strr   boolr)   r2   r<   r   r   r   <module>rB      s   *   / / %,J ,M3 M4 M*3 $ !(C5#:"67&'CD %XseTk%:; 	  #	<S S 	I 	I 	Ir   