a
    ž˜ë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 rVd dl	Z	e	j
Z
nej
Z
d dlm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ejejejfZdddddœdd„Zdddœdd„Zdddœdd„Z ddddœd d!„Z!ddd"d#œd$d%„Z"ddd&d'œd(d)„Z#d*d+d,œd-d.„Z$d/dd0œd1d2„Z%d/dd0œd3d4„Z&ejdk �rÖe	j'dd5�d/d/d0œd6d7„ƒZ(e	j'dd5�d/d/d0œd8d9„ƒZ)n8ej'dd5�d/d/d0œd:d7„ƒZ(ej'dd5�d/d/d0œd;d9„ƒZ)dd<d=œd>d?„Z*ejdd�G d@dA„ dAeje ƒƒZ+ej,Z,ej-j.Z.ej-j/Z/ej0Z0ej1Z1ej2Z2ej3Z3ej4Z4ej5Z5ej6Z7ej8Z8dS )Bé    )Ú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   ú\/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/cryptography/hazmat/asn1/asn1.pyr   "   s   
r   z
typing.Anyzdeclarative_asn1.Annotationr   ÚNone)Ú
field_typeÚ
annotationÚ
field_nameÚreturnc                 C  s(   | t v r$t|jtƒr$td|› d�ƒ‚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Úbool)r   r   c                 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_unionP   s
    ÿýr.   c                 C  sj   t jdk r| S t| tjƒr"| j} qt | ¡}tdd„ |D ƒƒ}||krJ| S t| ƒr\tj	| S t 
| ¡| S )N)r   é   c                 s  s   | ]}t |ƒV  qd S ©N)Ú_resolve_type_aliases©Ú.0Úargr   r   r   Ú	<genexpr>i   ó    z(_resolve_type_aliases.<locals>.<genexpr>)ÚsysÚversion_infor!   r+   ZTypeAliasTypeZ	__value__Úget_argsÚtupler.   r,   r-   )r   ÚargsZresolved_argsr   r   r   r1   \   s    

	
r1   r:   )Úmetadatar   r   c                 C  s²   d }d }d }| D ]�}t |tƒr>|d ur6td|› d�ƒ‚|j}qt |tjƒrh|d urbtd|› d�ƒ‚|}qt |tjƒr’|d urŒtd|› d�ƒ‚|}qtd|› �ƒ‚q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)r<   r   r>   r"   r?   Zraw_annotationr   r   r   Ú_extract_annotation€   s<    
ÿÿÿÿ
ÿÿrD   zdeclarative_asn1.AnnotatedType)r   r   r   c                   s   t | ƒ} t | ¡tju r4t| 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ƒr¦tdˆ› d�ƒ‚n|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!| ƒ�r„t | ¡}t"|ƒdk�rÌt#|v �rÌ|d t$d ƒu �rf|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ƒ‚ˆ �rPdd„ |	D ƒ}
t"|	ƒt"|
ƒk�rPtdƒ‚tj +|	¡}t#|v �r~tj (t |t ¡ ¡¡n|}npt | ¡t
ju �r¸t%t | ¡d	 ˆƒ}tj ,|¡}n<t | ¡tu �rêt%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 r0   )r&   Ú_type_to_variantr2   )r   r   r   Ú
<listcomp>  s   þz)_normalize_field_type.<locals>.<listcomp>c                 3  s   | ]}|j d uˆ kV  qd S r0   ©Útag_name©r3   Úv)Úare_union_types_taggedr   r   r5     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   rJ   rL   r   r   r   Ú	<setcomp>  r6   z(_normalize_field_type.<locals>.<setcomp>zBWhen using `asn1.Variant` in a union, the tags used must be unique).r1   r+   r-   Ú	AnnotatedrD   Ú__metadata__r9   r   rC   r?   ÚbuiltinsÚlistÚSetOfÚbytesr   Ú	BitStringÚ	IA5StringÚPrintableStringr$   ÚTLVr!   r"   r#   r>   r%   r)   rE   ÚTypeÚSequenceÚSetÚValueSetÚAnnotatedTypeÚcastr.   ÚlenÚNoneTyper&   Ú_normalize_field_typer   Zis_emptyÚOptionrK   ÚanyZChoiceZ
SequenceOfÚnon_root_python_to_rust)r   r   r   Ú_Z	root_typeZ
union_argsZoptional_typeÚannotated_typeZrust_field_typeÚvariantsÚtagsZrust_choice_typeÚ
inner_typer   )rN   r   r   rb   £   sÔ    
ÿûÿþ
ÿ
ÿ

ÿýþÿ

 ÿ
ÿÿ
ÿÿÿ
þþ
ÿÿû
ÿÿù
ÿÿ
rb   zdeclarative_asn1.Variant)Útr   r   c           	      C  sÔ   t  | ¡t ju }|r"t  | ¡d n| }t  |¡tu r¼t  |¡\}}t  |¡t jurZtdƒ‚t  |¡d }t|dƒrz|j}n
t	 
|¡}|ržt	 |t| j|ƒ¡}nt	 |t	 ¡ ¡}t	 t||¡S t	 |t| |ƒd ¡S 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"]]`.rE   )r+   r-   rP   r9   r   ÚLiteralr$   r)   rE   r   re   r^   rD   rQ   rC   rb   )	rk   r   Zis_annotatedrj   Ú
value_typeZtag_literalrK   Ú	rust_typeZann_typer   r   r   rH   @  s6    ÿ


þþýrH   zdict[str, type]z)dict[str, declarative_asn1.AnnotatedType])Ú
raw_fieldsr   c                 C  s,   i }|   ¡ D ]\}}t||ƒ}|||< q|S r0   )Úitemsrb   )ro   Úfieldsr   r   Zannotated_field_typer   r   r   Ú_annotate_fieldsk  s
    

rr   útype[U]©Úclsr   c                 C  s0   t j| dd�}tj | t|ƒ¡}t| d|ƒ d S ©NT)Úinclude_extrasrE   )r+   Úget_type_hintsr   rZ   r[   rr   Úsetattr©ru   ro   Úrootr   r   r   Ú_register_asn1_sequencex  s    r|   c                 C  s0   t j| dd�}tj | t|ƒ¡}t| d|ƒ d S rv   )r+   rx   r   rZ   r\   rr   ry   rz   r   r   r   Ú_register_asn1_set  s    r}   )Zkw_only_defaultc                 C  s@   t jdkr"tjddddd�| ƒ}ntjddd�| ƒ}t|ƒ |S ©Nr   FT©ÚreprÚeqZ
match_argsZkw_only)r€   r�   )r7   r8   ÚdataclassesÚ	dataclassr|   ©ru   Zdataclass_clsr   r   r   ÚsequenceŒ  s"    
ø	÷þýr…   c                 C  s@   t jdkr"tjddddd�| ƒ}ntjddd�| ƒ}t|ƒ |S r~   )r7   r8   r‚   rƒ   r}   r„   r   r   r   Úset£  s"    
ø	÷þýr†   c                 C  s"   t jddddd�| ƒ}t|ƒ |S ©NFTr   )r‚   rƒ   r|   r„   r   r   r   r…   ¼  s    üûc                 C  s"   t jddddd�| ƒ}t|ƒ |S r‡   )r‚   rƒ   r}   r„   r   r   r   r†   É  s    üûz#typing.Callable[[type[U]], type[U]])rm   r   c                   s$   t  ˆ¡‰ dd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.
    rs   rt   c                   s¶   t | tjƒstdƒ‚t| ƒ}|s2td| j› d�ƒ‚|D ]@}t|jˆƒs6td|j› d| j› dˆj› dt	|jƒj› d�	ƒ‚q6t
 ˆ 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: 'r=   c                 S  s   i | ]}|j |“qS r   )r   )r3   Úmemberr   r   r   Ú
<dictcomp>ú  r6   z0value_set.<locals>.decorator.<locals>.<dictcomp>rE   )Ú
issubclassÚenumÚEnumr$   rS   r   r!   r   Únamer&   r   r^   rC   rZ   r]   ry   )ru   Úmembersrˆ   ÚinnerZ	value_mapr{   ©rn   rm   r   r   Ú	decoratorã  s2    ÿÿþ
ýÿÿzvalue_set.<locals>.decorator)r   re   )rm   r‘   r   r�   r   Ú	value_set×  s    

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@   )9Ú
__future__r   rR   r‚   r‹   r7   r*   r+   r8   Ztyping_extensionsZLiteralStringZ"cryptography.hazmat.bindings._rustr   r   Z	rust_x509r&   ra   ÚTypeVarr	   r   r   rƒ   ÚGenericr   Z
decode_derZ
encode_derZCertificateZCertificateSigningRequestZCertificateRevocationListr    r%   r.   r1   rD   rb   rH   rr   r|   r}   Zdataclass_transformr…   r†   r’   r@   rT   rA   ZExplicitr#   rB   rX   rW   ZUTCTimeZGeneralizedTimerV   ZTlvrY   ZNullr   r   r   r   Ú<module>   sv   




ý$# +



-
