
    DjJ                    0   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     r ed          Znej        Z ej        dd	          Z ej        d
          Z ej        de
          Z ej        d           G d dej        eef                               Zej        Zej        Zej        ej        ej        fZd7dZd8dZd9dZ d:dZ!d;d!Z"d<d$Z#d=d(Z$d>d+Z%d>d,Z&ej        dk     r7 e	j'        d-          d?d.            Z( e	j'        d-          d?d/            Z)n6 ej'        d-          d?d0            Z( ej'        d-          d?d1            Z)d@d4Z* ej        d           G d5 d6ej        e                               Z+ej,        Z,ej-        j.        Z.ej-        j/        Z/ej0        Z0ej1        Z1ej2        Z2ej3        Z3ej4        Z4ej5        Z5ej6        Z7ej8        Z8dS )A    )annotationsN)      )declarative_asn1)x509r   
   TT)	covariantUTag)bound)frozenc                  (    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__     X/home/thesage/.hermes/venv/lib/python3.11/site-packages/cryptography/hazmat/asn1/asn1.pyr   r   "   s.          " HHHHHHHHr   r   
field_type
typing.Any
annotationdeclarative_asn1.Annotation
field_namer   returnNonec                v    | 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!   s      r   _check_x509_field_annotationsr+   D   s[    
 [  Z
0CX%N%N Fj F F F
 
 	
 !   r   typeboolc                    t          t          d          rt          j        t          j        fnt          j        f}t          j        |           |v S )N	UnionType)hasattrtypesr/   typingUnion
get_origin)r   union_typess     r   	_is_unionr6   P   sH     5+&&	&,''l_ 
 Z((K77r   c                |   t           j        dk     r| S t          | t          j                  r!| j        } t          | t          j                  !t          j        |           }t          d |D                       }||k    r| S t          |           rt          j	        |         S t          j
        |           |         S )N)r      c              3  4   K   | ]}t          |          V  d S N)_resolve_type_aliases).0args     r   	<genexpr>z(_resolve_type_aliases.<locals>.<genexpr>i   s+      EE/44EEEEEEr   )sysversion_infor'   r2   TypeAliasType	__value__get_argstupler6   r3   r4   )r   argsresolved_argss      r   r;   r;   \   s     '!!
Z!5
6
6 *)
 Z!5
6
6 * ?:&&DEEEEEEEM 	+ |M** Z((77r   metadatarD   c                   d }d }d }| D ]}t          |t                    r|t          d| d          |j        }4t          |t          j                  r|t          d| d          |}ft          |t          j                  r|t          d| d          |}t          d|           t	          j        |||          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)rG   r!   rJ   r(   rK   raw_annotations         r   _extract_annotationrQ      s?    GHD" I Ing.. 	I"&"& & &   %*GG(8(ABB 	I#&"& & &   &HH(8(=>> 	INNNN   "DDG~GGHHH&(   r   declarative_asn1.AnnotatedTypec                	   t          |           } t          j        |           t          j        u r,t	          | j                  }t          j        |           ^} }nt          j                    }|j	        ft          j        |           t          j        t          fvr?| t          j        t          j        t          t           t"          fvrt%          d d          | t&          u rGt)          |j        t,                    rt%          d d          |j        t%          d d          t1          | |           t3          | d          r| j        }t)          |t          j        j        t          j        j        t          j        j        f          st%          d|           t          j        t          j         t          j        |          |          S tC          |           r
t          j        |           }tE          |          dk    rtF          |v r|d         tI          d           u r|d	         n|d         }|t&          u rt%          d
          t1          ||           tK          |          }|j&        '                                st%          d          |j        t%          d          t          j        (                    |          }nt)          |j        t,                    rt%          d          fd|D             }	|	d	         j)        d utU          fd|	D                       rt%          d          r;d |	D             }
tE          |	          tE          |
          k    rt%          d          t          j        +                    |	          }tF          |v rCt          j        (                    t          j        |t          j                                        n|}nt          j        |           t          j        u rHtK          t          j        |           d	                   }t          j        ,                    |          }nwt          j        |           t          u rHtK          t          j        |           d	                   }t          j                            |          }nt          j-        |           }t          j        ||          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                R    g | ]#}|t          d           ut          |          $S r:   )r,   _type_to_variant)r<   r=   r!   s     r   
<listcomp>z)_normalize_field_type.<locals>.<listcomp>  s>       d4jj(( !j11(((r   c              3  2   K   | ]}|j         d uk    V  d S r:   tag_name)r<   vare_union_types_taggeds     r   r>   z(_normalize_field_type.<locals>.<genexpr>  sD         4',BB     r   zbWhen using `asn1.Variant` in a union, all the other types in the union must also be `asn1.Variant`c                    h | ]	}|j         
S r   r[   )r<   r]   s     r   	<setcomp>z(_normalize_field_type.<locals>.<setcomp>  s    555q
555r   zBWhen using `asn1.Variant` in a union, the tags used must be unique).r;   r2   r4   	AnnotatedrQ   __metadata__rC   r   rO   rK   builtinslistSetOfbytesr   	BitString	IA5StringPrintableStringr*   TLVr'   r(   r)   rJ   r+   r0   rT   TypeSequenceSetValueSetAnnotatedTypecastr6   lenNoneTyper,   _normalize_field_typer   is_emptyOptionr\   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^   s    `           @r   rs   rs      si    'z22J $$(888()@*MM
44
QQ%022
"*%%hmU-CCCNL

 
 *j * * *
 
 	
 Sj)844 		H* H H H   +G* G G G  
 "*j*EEEz?++ iO,	 %. %) %.
 
 	C AiAABBB-K(-y99:
 
 	
 
:		 [O_Z00
z??aH
$:$: ",A$t**!<!<
1*Q-  ##*   *z:   3=*MMN!,5577 ?   !-!  
 /3::>JJOO *-x88 !     %  H &.a[%9%E"    !       E  
 & 55H555x==CII--#)  
  04;;HEE z)) !%,,$2(*:*E*G*G    & O 
	:	&	&(-	7	7*OJ''*J
 

 +/:::FF		:	&	&%	/	/*OJ''*J
 

 +/55jAA*B:NN)/:FFFr   tdeclarative_asn1.Variantc                   t          j        |           t           j        u }|rt          j        |           d         n| }t          j        |          t          u rt          j        |          \  }}t          j        |          t           j        urt          d          t          j        |          d         }t          |d          r|j        }nt          j
        |          }|r)t          j        |t          | j        |                    }n&t          j        |t          j                              }t          j        t          ||          S t          j        |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"]]`.rT   )r2   r4   ra   rC   r   Literalr*   r0   rT   r   ry   ro   rQ   rb   rO   rs   )	r   r!   is_annotatedr   
value_typetag_literalr\   	rust_typeann_types	            r   rX   rX   @  sj    $Q''6+;;L*6=##A&&AJ $$//"(/*"="=
K[))??;  
 ?;//2:// 	M"0II(@LLI 		'5#ANJ?? HH
 (5 +-- H
  '8DDD  '!!Z00
 
 	
r   
raw_fieldsdict[str, type])dict[str, declarative_asn1.AnnotatedType]c                h    i }|                                  D ]\  }}t          ||          }|||<   |S r:   )itemsrs   )r   fieldsr!   r   annotated_field_types        r   _annotate_fieldsr   k  sM     F","2"2"4"4 2 2
J  5ZLL1zMr   clstype[U]c                    t          j        | d          }t          j                            | t          |                    }t          | d|           d S NT)include_extrasrT   )r2   get_type_hintsr   rk   rl   r   setattrr   r   roots      r   _register_asn1_sequencer   x  sP    &s4@@@J ))#/?
/K/KLLDC$'''''r   c                    t          j        | d          }t          j                            | t          |                    }t          | d|           d S r   )r2   r   r   rk   rm   r   r   r   s      r   _register_asn1_setr     sP    &s4@@@J $$S*::*F*FGGDC$'''''r   )kw_only_defaultc                    t           j        dk    r" t          j        dddd          |           }n t          j        dd          |           }t	          |           |S Nr   FTrepreq
match_argskw_only)r   r   )r?   r@   dataclasses	dataclassr   r   dataclass_clss     r   sequencer     s     w&&	K1 ! 	 	 	 	 	MMK1    M 	 ...r   c                    t           j        dk    r" t          j        dddd          |           }n t          j        dd          |           }t	          |           |S r   )r?   r@   r   r   r   r   s     r   setr     s     w&&	K1 ! 	 	 	 	 	MMK1    M 	=)))r   c                f     t          j        dddd          |           }t          |           |S NFTr   )r   r   r   r   s     r   r   r     sN    
-	
 
 

   	 ...r   c                f     t          j        dddd          |           }t          |           |S r   )r   r   r   r   s     r   r   r     sN    
-	
 
 

   	=)))r   r   #typing.Callable[[type[U]], type[U]]c                @     t          j                   d f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                ,   t          | t          j                  st          d          t	          |           }|st          d| j         d          |D ]Y}t          |j                  sBt          d|j         d| j         dj         dt          |j                  j         d	          Zt          j        t          j                              }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: 'rI   c                    i | ]
}|j         |S r   )r   )r<   members     r   
<dictcomp>z0value_set.<locals>.decorator.<locals>.<dictcomp>  s    @@@fV\6@@@r   rT   )
issubclassenumEnumr*   rd   r   r'   r   namer,   r   ro   rO   rk   rn   r   )r   membersr   inner	value_mapr   r   r   s         r   	decoratorzvalue_set.<locals>.decorator  s[   #ty)) 	J   s)) 	KclKKK    	 	FflJ77 7v{ 7 7CL 7 7"+7 7 V\**37 7 7   !.'244
 

 A@@@@	$--c5)DD_d+++
r   r   r   r"   r   )r   ry   )r   r   r   s   ` @r   	value_setr     sA     !8DDI      : r   c                      e Zd ZU ded<   dS )rL   r   r   N)r   r   r   r   r   r   r   rL   rL     s         HHHHHr   rL   )r   r   r   r    r!   r   r"   r#   )r   r,   r"   r-   )r   r   r"   r   )rG   rD   r!   r   r"   r    )r   r   r!   r   r"   rR   )r   r   r!   r   r"   r   )r   r   r"   r   )r   r   r"   r#   r   )r   r,   r"   r   )9
__future__r   rc   r   r   r?   r1   r2   r@   typing_extensionsLiteralString"cryptography.hazmat.bindings._rustr   r   	rust_x509r,   rr   TypeVarr
   r   r   r   Genericr   
decode_der
encode_derCertificateCertificateSigningRequestCertificateRevocationListr&   r+   r6   r;   rQ   rs   rX   r   r   r   dataclass_transformr   r   r   rL   re   rM   Explicitr)   rN   ri   rh   UTCTimeGeneralizedTimerg   Tlvrj   Nullr   r   r   <module>r      s  
 # " " " " "       



  g%3MM(M ? ? ? ? ? ? @ @ @ @ @ @gtDzzHH~HFN3$'''FN3fnU-000 d###    fnQV$   $#, (
(
 ''	
 	
 	
 	
	8 	8 	8 	8!8 !8 !8 !8H       FXG XG XG XGz(
 (
 (
 (
V
 
 
 
( ( ( (( ( ( ( g**4@@@   A@, +*4@@@   A@ 0  V555
 
 
 65
  V555
 
 
 65
) ) ) )Z d###    fnQ   $# 	$-$-"2&	

""2&	r   