o
    =j„9  ã                   @  sè  d dl mZ d dlZd dlZd dlZd dlZd dlZejdk r'd dlZej	Z	nej	Z	d dl
mZ ejdk r:edƒZnejZejddd�Ze d	¡Zejd
e	d�Zejdd�G dd„ dejeef ƒƒZejZejZd9dd„Zd:dd„Zd;dd„Zd<d"d#„Zd=d'd(„Zd>d,d-„Zd>d.d/„Zejdk r¨ejdd0�d?d1d2„ƒZejdd0�d?d3d4„ƒZ nejdd0�d?d5d2„ƒZejdd0�d?d6d4„ƒZ ejdd�G d7d8„ d8eje ƒƒZ!ej"Z"ej#j$Z$ej#j%Z%ej&Z&ej'Z'ej(Z(ej)Z)ej*Z*ej+Z+ej,Z-ej.Z.dS )@é    )ÚannotationsN)é   é   )Údeclarative_asn1©r   é
   ÚTT)Ú	covariantÚUÚTag)Úbound)Úfrozenc                   @  s"   e Zd ZU dZded< ded< dS )ÚVarianta  
    A tagged variant for CHOICE fields with the same underlying type.

    Use this when you have multiple CHOICE alternatives with the same type
    and need to distinguish between them:

        foo: (
            Annotated[Variant[int, typing.Literal["IntA"]], Implicit(0)]
            | Annotated[Variant[int, typing.Literal["IntB"]], Implicit(1)]
        )

    Usage:
        example = Example(foo=Variant(5, "IntA"))
        decoded.foo.value  # The int value
        decoded.foo.tag    # "IntA" or "IntB"
    r
   ÚvalueÚstrÚtagN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© r   r   úgC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\cryptography/hazmat/asn1/asn1.pyr       s   
 r   Ú
field_typeÚtypeÚreturnÚboolc                 C  s,   t tdƒrtjtjfntjf}t | ¡|v S )NÚ	UnionType)ÚhasattrÚtypesr   ÚtypingÚUnionÚ
get_origin)r   Zunion_typesr   r   r   Ú	_is_union;   s
   ÿýr#   ÚmetadataÚtupleÚ
field_namer   údeclarative_asn1.Annotationc                 C  s°   d }d }d }| D ]G}t |tƒr|d urtd|› d�ƒ‚|j}qt |tjƒr4|d ur1td|› d�ƒ‚|}qt |tjƒrI|d urFtd|› d�ƒ‚|}qtd|› �ƒ‚tj|||d�S )Nz-multiple DEFAULT annotations found in field 'ú'z7multiple IMPLICIT/EXPLICIT annotations found in field 'z*multiple SIZE annotations found in field 'zunsupported annotation: )ÚdefaultÚencodingÚsize)Ú
isinstanceÚDefaultÚ	TypeErrorr   r   ÚEncodingÚSizeÚ
Annotation)r$   r&   r)   r*   r+   Zraw_annotationr   r   r   Ú_extract_annotationG   s<   
ÿÿÿÿ
ÿÿr2   ú
typing.Anyúdeclarative_asn1.AnnotatedTypec                   sÄ  t  | ¡t ju rt| jˆƒ}t  | ¡^} }nt ¡ }|jd ur<t  | ¡t	j
tfvr<| t	jt	jtttfvr<tdˆ› d�ƒ‚| tu r[t|jtƒrNtdˆ› d�ƒ‚|jd ur[tdˆ› d�ƒ‚t| dƒr€| j}t|tjjtjjfƒsutd|› �ƒ‚t t  tj|¡|¡S t| ƒ�r$t  | ¡}t|ƒdkrÊt |v rÊ|d t!d ƒu r |d	 n|d }|tu r¬td
ƒ‚t"|ˆƒ}|j# $¡ sºtdƒ‚|jd urÃtdƒ‚tj %|¡}n’t|jtƒrÔtdƒ‚‡fdd„|D ƒ}	|	d	 j&d u‰ t'‡ fdd„|	D ƒƒrótdƒ‚ˆ �r
dd„ |	D ƒ}
t|	ƒt|
ƒk�r
tdƒ‚tj (|	¡}t |v �r!tj %t |t ¡ ¡¡n|}n8t  | ¡t	j
u �r>t"t  | ¡d	 ˆƒ}tj )|¡}nt  | ¡tu �rWt"t  | ¡d	 ˆƒ}tj |¡}nt *| ¡}t ||¡S )Nzfield 'z­' has a SIZE annotation, but SIZE annotations are only supported for fields of types: [SEQUENCE OF, SET OF, BIT STRING, OCTET STRING, UTF8String, PrintableString, IA5String]zW' has an IMPLICIT annotation, but IMPLICIT annotations are not supported for TLV types.zT' has a DEFAULT annotation, but DEFAULT annotations are not supported for TLV types.Ú__asn1_root__zunsupported root type: é   é   r   z=optional TLV types (`TLV | None`) are not currently supportedzƒoptional (`X | None`) types cannot have `X` annotated: annotations must apply to the union (i.e: `Annotated[X | None, annotation]`)z@optional (`X | None`) types should not have a DEFAULT annotationzCCHOICE (`X | Y | ...`) types should not have an IMPLICIT annotationc                   s"   g | ]}|t d ƒurt|ˆ ƒ‘qS ©N)r   Ú_type_to_variant)Ú.0Úarg)r&   r   r   Ú
<listcomp>Â   s    
ýÿz)_normalize_field_type.<locals>.<listcomp>c                 3  s   � | ]
}|j d uˆ kV  qd S r8   ©Útag_name©r:   Úv)Úare_union_types_taggedr   r   Ú	<genexpr>Ë   s
   € ÿ
ÿz(_normalize_field_type.<locals>.<genexpr>zbWhen using `asn1.Variant` in a union, all the other types in the union must also be `asn1.Variant`c                 S  s   h | ]}|j ’qS r   r=   r?   r   r   r   Ú	<setcomp>Õ   s    z(_normalize_field_type.<locals>.<setcomp>zBWhen using `asn1.Variant` in a union, the tags used must be unique)+r    r"   Ú	Annotatedr2   Ú__metadata__Úget_argsr   r1   r+   ÚbuiltinsÚlistÚSetOfÚbytesr   Ú	BitStringÚ	IA5StringÚPrintableStringr.   ÚTLVr,   r*   ÚImplicitr)   r   r5   ÚTypeÚSequenceÚSetÚAnnotatedTypeÚcastr#   ÚlenÚNoneTyper   Ú_normalize_field_typeÚ
annotationZis_emptyÚOptionr>   ÚanyZChoiceZ
SequenceOfÚnon_root_python_to_rust)r   r&   rX   Ú_Z	root_typeZ
union_argsZoptional_typeÚannotated_typeZrust_field_typeÚvariantsÚtagsZrust_choice_typeÚ
inner_typer   )rA   r&   r   rW   j   sÄ   
ÿûÿþ
ÿ
ÿ

ÿ
þÿ

ÿÿ

ÿ
ÿÿ
þþÿÿ
ûÿÿù
ÿÿ
rW   Útúdeclarative_asn1.Variantc           	      C  sÐ   t  | ¡t ju }|rt  | ¡d n| }t  |¡tu r^t  |¡\}}t  |¡t jur-tdƒ‚t  |¡d }t|dƒr=|j}nt	 
|¡}|rOt	 |t| j|ƒ¡}nt	 |t	 ¡ ¡}t	 t||¡S t	 |t| |ƒd ¡S )Nr   z˜When using `asn1.Variant` in a type annotation, the second type parameter must be a `typing.Literal` type. E.g: `Variant[int, typing.Literal["MyInt"]]`.r5   )r    r"   rD   rF   r   ÚLiteralr.   r   r5   r   r[   rS   r2   rE   r1   rW   )	ra   r&   Zis_annotatedr`   Z
value_typeZtag_literalr>   Z	rust_typeZann_typer   r   r   r9   ú   s6   ÿ


þþýr9   Ú
raw_fieldsúdict[str, type]ú)dict[str, declarative_asn1.AnnotatedType]c                 C  s,   i }|   ¡ D ]\}}t||ƒ}|||< q|S r8   )ÚitemsrW   )rd   Úfieldsr&   r   Zannotated_field_typer   r   r   Ú_annotate_fields%  s
   

ri   Úclsútype[U]ÚNonec                 C  ó0   t j| dd�}tj | t|ƒ¡}t| d|ƒ d S ©NT)Úinclude_extrasr5   )r    Úget_type_hintsr   rP   rQ   ri   Úsetattr©rj   rd   Úrootr   r   r   Ú_register_asn1_sequence2  ó   rt   c                 C  rm   rn   )r    rp   r   rP   rR   ri   rq   rr   r   r   r   Ú_register_asn1_set9  ru   rv   )Zkw_only_defaultc                 C  ó@   t jdkrtjddddd�| ƒ}n	tjddd�| ƒ}t|ƒ |S ©Nr   FT©ÚreprÚeqÚ
match_argsÚkw_only)rz   r{   )ÚsysÚversion_infoÚdataclassesÚ	dataclassrt   ©rj   Zdataclass_clsr   r   r   ÚsequenceF  ó"   
ø	÷þýrƒ   c                 C  rw   rx   )r~   r   r€   r�   rv   r‚   r   r   r   Úset]  r„   r…   c                 C  ó"   t jddddd�| ƒ}t|ƒ |S ©NFTry   )r€   r�   rt   r‚   r   r   r   rƒ   v  ó   üûc                 C  r†   r‡   )r€   r�   rv   r‚   r   r   r   r…   ƒ  rˆ   c                   @  s   e Zd ZU ded< dS )r-   r
   r   N)r   r   r   r   r   r   r   r   r-   ’  s   
 r-   )r   r   r   r   )r$   r%   r&   r   r   r'   )r   r3   r&   r   r   r4   )ra   r3   r&   r   r   rb   )rd   re   r   rf   )rj   rk   r   rl   )rj   rk   r   rk   )/Ú
__future__r   rG   r€   r~   r   r    r   Ztyping_extensionsZLiteralStringZ"cryptography.hazmat.bindings._rustr   r   rV   ÚTypeVarr   r
   r   r�   ÚGenericr   Z
decode_derZ
encode_derr#   r2   rW   r9   ri   rt   rv   Zdataclass_transformrƒ   r…   r-   rI   r/   ZExplicitrO   r0   rM   rL   ZUTCTimeZGeneralizedTimerK   ZTlvrN   ZNullr   r   r   r   Ú<module>   sf   







# 

+








