o
    àý°jÐJ  ã                   @  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 rÄe	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   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/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ƒs‚td|› �ƒ‚t t  tj|¡|¡S t!| ƒ�r8t | ¡}t"|ƒdkrÝt#|v rÝ|d t$d ƒu r­|d	 n|d }|tu r¹td
ƒ‚t||ˆƒ 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 �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 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 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   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"]]`.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   




ý



$
# 

+








-
