U
    Óøïc×  ã                	   @   sX   d Z dgZddlZddlZejejejejejej	ej
ejejf	Zdeedœdd„ZdS )z&An implementation of RFC4013 SASLprep.Úsaslprepé    NT)ÚdataÚreturnc                    s´   |rt tjf }nt }tj‰tj‰d ‡‡fdd„| D ƒ¡} tj d| ¡} tj	}|| d ƒr~|| d ƒspt
dƒ‚|tjf }n
||f }| D ]"‰ t‡ fdd	„|D ƒƒrŒt
d
ƒ‚qŒ| S )a¿  An implementation of RFC4013 SASLprep.

    :param data:
        The string to SASLprep.
    :param prohibit_unassigned_code_points:
        RFC 3454 and RFCs for various SASL mechanisms distinguish between
        `queries` (unassigned code points allowed) and
        `stored strings` (unassigned code points prohibited). Defaults
        to ``True`` (unassigned code points are prohibited).

    :return: The SASLprep'ed version of `data`.
    Ú c                    s$   g | ]}ˆ |ƒsˆ|ƒrd n|‘qS )ú © )Ú.0Úelt)Úin_table_b1Úin_table_c12r   úE/tmp/pip-unpacked-wheel-0kb_yl26/pyhanko/pdf_utils/crypt/_saslprep.pyÚ
<listcomp>C   s    ÿzsaslprep.<locals>.<listcomp>ÚNFKCr   éÿÿÿÿz$SASLprep: failed bidirectional checkc                 3   s   | ]}|ˆ ƒV  qd S )Nr   )r   Zin_table)Úcharr   r   Ú	<genexpr>\   s     zsaslprep.<locals>.<genexpr>z+SASLprep: failed prohibited character check)Ú_PROHIBITEDÚ
stringprepÚin_table_a1r   r
   ÚjoinÚunicodedataÚ	ucd_3_2_0Ú	normalizeÚin_table_d1Ú
ValueErrorÚin_table_d2Úany)r   Zprohibit_unassigned_code_pointsZ
prohibitedr   r   )r   r
   r   r   r   *   s.    ÿÿ
ÿ)T)Ú__doc__Ú__all__r   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   Ústrr   r   r   r   r   Ú<module>   s   ô