o
    j9                     @  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 re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   c/var/www/html/fyndo/pharma/fyndo/venv/lib/python3.10/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   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,   raw_annotationr   r   r   _extract_annotationG   s<   

r4   
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rt |v r|d t!d u r|d	 n|d }|tu rtd
t"|}|j#$ std|jd urtdtj%|}nt|jtrtdfdd|D }	|	d	 j&d u t' fdd|	D rt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 supportedzoptional (`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 r:   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?   rA   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"   	Annotatedr4   __metadata__get_argsr   r2   r,   builtinslistSetOfbytesr   	BitString	IA5StringPrintableStringr/   TLVr-   r+   Implicitr*   r   r7   TypeSequenceSetAnnotatedTypecastr$   lenNoneTyper   _normalize_field_type
annotationis_emptyOptionr@   anyChoice
SequenceOfnon_root_python_to_rust)r   r'   rZ   _	root_type
union_argsoptional_typeannotated_typerust_field_typevariantstagsrust_choice_type
inner_typer   )rC   r'   r   rY   j   s   
	













rY   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   zWhen using `asn1.Variant` in a type annotation, the second type parameter must be a `typing.Literal` type. E.g: `Variant[int, typing.Literal["MyInt"]]`.r7   )r    r"   rF   rH   r   Literalr/   r   r7   r   r`   rU   r4   rG   r2   rY   )	rk   r'   is_annotatedrj   
value_typetag_literalr@   	rust_typeann_typer   r   r   r;      s6   


r;   
raw_fieldsdict[str, type])dict[str, declarative_asn1.AnnotatedType]c                 C  s,   i }|   D ]\}}t||}|||< q|S r:   )itemsrY   )rs   fieldsr'   r   annotated_field_typer   r   r   _annotate_fields%  s
   

ry   clstype[U]Nonec                 C  0   t j| dd}tj| t|}t| d| d S NT)include_extrasr7   )r    get_type_hintsr   rR   rS   ry   setattrrz   rs   rootr   r   r   _register_asn1_sequence2     r   c                 C  r}   r~   )r    r   r   rR   rT   ry   r   r   r   r   r   _register_asn1_set9  r   r   )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)r   r   )sysversion_infodataclasses	dataclassr   rz   dataclass_clsr   r   r   sequenceF  "   
	r   c                 C  r   r   )r   r   r   r   r   r   r   r   r   set]  r   r   c                 C  "   t jddddd| }t| |S NFTr   )r   r   r   r   r   r   r   r   v     c                 C  r   r   )r   r   r   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   r5   r'   r   r   r6   )rk   r5   r'   r   r   rl   )rs   rt   r   ru   )rz   r{   r   r|   )rz   r{   r   r{   )/
__future__r   rI   r   r   r   r    r   typing_extensionsLiteralString"cryptography.hazmat.bindings._rustr   r   rX   TypeVarr   r
   r   r   Genericr   
decode_der
encode_derr$   r4   rY   r;   ry   r   r   dataclass_transformr   r   r.   rK   r0   ExplicitrQ   r1   rO   rN   UTCTimeGeneralizedTimerM   TlvrP   Nullr   r   r   r   <module>   sf   







# 

+








