o
    okjJ                     @  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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 d dlmZ ejdk rDe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ejejejfZdCddZdDddZdEddZ dFd"d#Z!dGd%d&Z"dHd)d*Z#dId.d/Z$dJd2d3Z%dJd4d5Z&ejdk re	j'dd6dKd7d8Z(e	j'dd6dKd9d:Z)nej'dd6dKd;d8Z(ej'dd6dKd<d:Z)dLd?d@Z*ejddG dAdB dBeje Z+ej,Z,ej-j.Z.ej-j/Z/ej0Z0ej1Z1ej2Z2ej3Z3ej4Z4ej5Z5ej6Z7ej8Z8dS )M    )annotationsN)      )declarative_asn1)x509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   [/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/cryptography/hazmat/asn1/asn1.pyr   "   s   
 r   
field_type
typing.Any
annotationdeclarative_asn1.Annotation
field_namer   returnNonec                 C  s,   | t v rt|jtrtd| dd S d S )Nfield 'zY' has an IMPLICIT annotation, but IMPLICIT annotations are not supported for X.509 types.)_X509_TYPES
isinstanceencodingImplicit	TypeError)r   r   r   r   r   r   _check_x509_field_annotationsD   s
   
r'   type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_unionP   s
   r1   c                 C  st   t jdk r| S t| tjr| j} t| tjst| }tdd |D }||kr*| S t| r3tj	| S t
| | S )N)r      c                 s  s    | ]}t |V  qd S N)_resolve_type_aliases.0argr   r   r   	<genexpr>i   s    z(_resolve_type_aliases.<locals>.<genexpr>)sysversion_infor#   r-   TypeAliasType	__value__get_argstupler1   r.   r/   )r   argsresolved_argsr   r   r   r4   \   s   


	r4   metadatar>   c                 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: )defaultr$   size)r#   Defaultr&   r   r   EncodingSize
Annotation)rA   r   rC   r$   rD   raw_annotationr   r   r   _extract_annotation   s<   

rJ   declarative_asn1.AnnotatedTypec                   s  t | } 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rRtd d|jd ur_td dt| | t| dr| j}t|tjjtjjtjjfstd| tt tj||S t!| r8t| }t"|dkrt#|v r|d t$d u r|d	 n|d }|tu rtd
t|| 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 rtd rdd |	D }
t"|	t"|
krtdtj+|	}t#|v r5tj(t|t n|}n8t| t
ju rRt%t| d	 }tj,|}nt| tu rkt%t| d	 }tj|}nt-| }t||S )Nr!   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 r3   )r(   _type_to_variantr5   )r   r   r   
<listcomp>  s
    z)_normalize_field_type.<locals>.<listcomp>c                 3  s    | ]
}|j d u kV  qd S r3   tag_namer6   v)are_union_types_taggedr   r   r8     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   rQ   rS   r   r   r   	<setcomp>  s    z(_normalize_field_type.<locals>.<setcomp>zBWhen using `asn1.Variant` in a union, the tags used must be unique).r4   r-   r/   	AnnotatedrJ   __metadata__r=   r   rH   rD   builtinslistSetOfbytesr   	BitString	IA5StringPrintableStringr&   TLVr#   r$   r%   rC   r'   r+   rL   TypeSequenceSetValueSetAnnotatedTypecastr1   lenNoneTyper(   _normalize_field_typer   is_emptyOptionrR   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   )rU   r   r   ri      s   
	














ri   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"]]`.rL   )r-   r/   rW   r=   r   Literalr&   r+   rL   r   ro   re   rJ   rX   rH   ri   )	rz   r   is_annotatedry   
value_typetag_literalrR   	rust_typeann_typer   r   r   rO   @  s6   


rO   
raw_fieldsdict[str, type])dict[str, declarative_asn1.AnnotatedType]c                 C  s,   i }|   D ]\}}t||}|||< q|S r3   )itemsri   )r   fieldsr   r   annotated_field_typer   r   r   _annotate_fieldsk  s
   

r   clstype[U]c                 C  0   t j| dd}tj| t|}t| d| d S NT)include_extrasrL   )r-   get_type_hintsr   ra   rb   r   setattrr   r   rootr   r   r   _register_asn1_sequencex     r   c                 C  r   r   )r-   r   r   ra   rc   r   r   r   r   r   r   _register_asn1_set  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   )r9   r:   dataclasses	dataclassr   r   dataclass_clsr   r   r   sequence  "   
	r   c                 C  r   r   )r9   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        c                 C  r   r   )r   r   r   r   r   r   r   r     r   r~   #typing.Callable[[type[U]], type[U]]c                   s   t  d fdd}|S )a"  
    A class decorator that registers an `enum.Enum` subclass as an
    ASN.1 value set of the given underlying type. All the member
    values must be instances of `value_type`. Members are encoded as
    their value; decoding fails if the decoded value does not match
    any member.
    r   r   r   c                   s   t | tjs
tdt| }|std| j d|D ] }t|js;td|j d| j dj dt	|jj d	qt
 t
 }d	d
 |D }t
j| ||}t| d| | S )Nz8value sets can only be defined from enum.Enum subclasseszvalue set 'z' must have at least one memberzmember 'z' of value set 'z' must have a value of type 'z	', got: 'rB   c                 S  s   i | ]}|j |qS r   )r   )r6   memberr   r   r   
<dictcomp>  s    z0value_set.<locals>.decorator.<locals>.<dictcomp>rL   )
issubclassenumEnumr&   rZ   r   r#   r   namer(   r   re   rH   ra   rd   r   )r   membersr   inner	value_mapr   r   r~   r   r   	decorator  s4   
zvalue_set.<locals>.decoratorNr   r   r   r   )r   ro   )r~   r   r   r   r   	value_set  s   

r   c                   @  s   e Zd ZU ded< dS )rE   r   r   N)r   r   r   r   r   r   r   r   rE     s   
 rE   )r   r   r   r   r   r   r   r    )r   r(   r   r)   )r   r   r   r   )rA   r>   r   r   r   r   )r   r   r   r   r   rK   )rz   r   r   r   r   r{   )r   r   r   r   )r   r   r   r    r   )r~   r(   r   r   )9
__future__r   rY   r   r   r9   r,   r-   r:   typing_extensionsLiteralString"cryptography.hazmat.bindings._rustr   r   	rust_x509r(   rh   TypeVarr	   r   r   r   Genericr   
decode_der
encode_derCertificateCertificateSigningRequestCertificateRevocationListr"   r'   r1   r4   rJ   ri   rO   r   r   r   dataclass_transformr   r   r   rE   r[   rF   Explicitr%   rG   r_   r^   UTCTimeGeneralizedTimer]   Tlvr`   Nullr   r   r   r   <module>   sx   








$
# 

+








-
