o
    <ii<                     @  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 rEd dlZej	Z	ejdk r8ej
Z
ejZejZejZnej
Z
ejZejZejZnej
Z
ejZejZejZej	Z	ejdk r^edZnejZd dlm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d:ddZd;ddZd<dd Zd=d#d$Z d>d(d)Z!d?d-d.Z"d?d/d0Z#ejdk rej$dd1d@d2d3Z%ej$dd1d@d4d5Z&nej$dd1d@d6d3Z%ej$dd1d@d7d5Z&ejddG d8d9 d9e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j0Z0ej1Z1ej2Z3ej4Z4dS )A    )annotationsN)      )r   	   r   
   )declarative_asn1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   \/root/parts/websockify/install/lib/python3.10/site-packages/cryptography/hazmat/asn1/asn1.pyr   2   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_type_origin)r   union_typesr   r   r   	_is_unionM   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_annotationY   s<   

r5   
typing.Anydeclarative_asn1.AnnotatedTypec                   s  t | tu rt| j}t| ^} }nt }|jd ur8t | tj	t
fvr8| tjtjtttfvr8td d| tu rWt|jtrJtd d|jd urWtd dt| dr|| j}t|tjjtjjfsqt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|}n4t | tj	u r7t"t| d	 }tj)|}nt | t
u rNt"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@   rB   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#   	Annotatedr5   __metadata__get_type_argsr   r3   r-   builtinslistSetOfbytesr   	BitString	IA5StringPrintableStringr0   TLVr.   r,   Implicitr+   r   r8   TypeSequenceSetAnnotatedTyper!   castr%   lenNoneTyper   _normalize_field_type
annotationis_emptyOptionrA   anyChoice
SequenceOfnon_root_python_to_rust)r   r(   r[   _	root_type
union_argsoptional_typeannotated_typerust_field_typevariantstagsrust_choice_type
inner_typer   )rD   r(   r   rZ   |   s   
	












rZ   tdeclarative_asn1.Variantc           	      C  s   t | tu }|rt| d n| }t |tu rWt|\}}t |tjur'tdt|d }t|dr6|j}nt	
|}|rHt	|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"]]`.r8   )r#   rG   rI   r   r!   Literalr0   r   r8   r   ra   rV   r5   rH   r3   rZ   )	rl   r(   is_annotatedrk   
value_typetag_literalrA   	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;   )itemsrZ   )rt   fieldsr(   r   annotated_field_typer   r   r   _annotate_fields7  s
   

rz   clstype[U]Nonec                 C  .   t | dd}tj| t|}t| d| d S NT)include_extrasr8   )get_type_hintsr   rS   rT   rz   setattrr{   rt   rootr   r   r   _register_asn1_sequenceD     r   c                 C  r~   r   )r   r   rS   rU   rz   r   r   r   r   r   _register_asn1_setK  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   r{   dataclass_clsr   r   r   sequenceZ  "   
	r   c                 C  r   r   )r   r   r   r   r   r   r   r   r   setq  r   r   c                 C  "   t jddddd| }t| |S NFTr   )r   r   r   r   r   r   r   r        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   r6   r(   r   r   r7   )rl   r6   r(   r   r   rm   )rt   ru   r   rv   )r{   r|   r   r}   )r{   r|   r   r|   )5
__future__r   rJ   r   r   r    r!   r   typing_extensionsLiteralStringr   get_argsrI   
get_originr#   rG   r   rY   "cryptography.hazmat.bindings._rustr   TypeVarr	   r   r   r   Genericr   
decode_der
encode_derr%   r5   rZ   r<   rz   r   r   dataclass_transformr   r   r/   rL   r1   ExplicitrR   r2   rP   rO   UTCTimeGeneralizedTimerN   TlvrQ   Nullr   r   r   r   <module>   s   








# 

+








