
    ]j9                       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  rd dlZej                  Z	nej                  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ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 d dZ	 	 	 	 d!dZd"dZd"dZej                  dk  r5 ej<                  d      d#d       Z ej<                  d      d#d       Z n4 ej<                  d      d#d       Z ej<                  d      d#d       Z  ej$                  d       G d dej&                  e                Z!ejD                  Z"ejF                  jH                  Z$ejF                  jJ                  Z%ejL                  Z&ejN                  Z'ejP                  Z(ejR                  Z)ejT                  Z*ejV                  Z+ejX                  Z-ej\                  Z.y)$    )annotationsN)      )declarative_asn1r   
   TT)	covariantUTag)bound)frozenc                  &    e Zd ZU dZded<   ded<   y)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__     G/root/env/lib/python3.12/site-packages/cryptography/hazmat/asn1/asn1.pyr   r       s    " H	Hr   r   c                    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)
field_typeunion_typess     r   	_is_unionr%   ;   sF     5+& 
&,,'ll_ 
 Z(K77r   c                z   d }d }d }| D ]  }t        |t              r|t        d| d      |j                  }1t        |t        j
                        r|t        d| d      |}_t        |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: )defaultencodingsize)
isinstanceDefault	TypeErrorr   r   EncodingSize
Annotation)metadata
field_namer(   r)   r*   raw_annotations         r   _extract_annotationr4   G   s    GHD" Ing.""|1&  %**G(8(A(AB#"|1&  &H(8(=(=>@AN  "D6~6FGHH-I0 &&( r   c                j	   t        j                  |       t         j                  u r.t        | j                  |      }t        j
                  |       ^} }nt        j                         }|j                  kt        j                  |       t        j                  t        fvr@| t        j                  t        j                  t        t        t         fvrt#        d| d      | t$        u rDt'        |j(                  t*              rt#        d| d      |j,                  t#        d| d      t/        | d      r| j0                  }t'        |t        j2                  j4                  t        j2                  j6                  f      st#        d|       t        j8                  t        j:                  t        j2                  |      |      S t=        |       rt        j
                  |       }t?        |      dk(  rt@        |v r|d   tC        d       u r|d	   n|d   }|t$        u rt#        d
      tE        ||      }|jF                  jI                         st#        d      |j,                  t#        d      t        j2                  jK                  |      }n t'        |j(                  t*              rt#        d      |D 	cg c]  }	|	tC        d       urtM        |	|       }
}	|
d	   jN                  d utQ        fd|
D              rt#        d      r;|
D ch c]  }|jN                   }}t?        |
      t?        |      k7  rt#        d      t        j2                  jS                  |
      }t@        |v rEt        j2                  jK                  t        j8                  |t        j                                     n|}nt        j                  |       t        j                  u rBtE        t        j
                  |       d	   |      }t        j2                  jU                  |      }nrt        j                  |       t        u rBtE        t        j
                  |       d	   |      }t        j2                  j                  |      }nt        jV                  |       }t        j8                  ||      S c c}	w c c}w )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              3  @   K   | ]  }|j                   d uk7    y wN)tag_name).0vare_union_types_taggeds     r   	<genexpr>z(_normalize_field_type.<locals>.<genexpr>   s(       4',BBs   zbWhen using `asn1.Variant` in a union, all the other types in the union must also be `asn1.Variant`zBWhen using `asn1.Variant` in a union, the tags used must be unique),r    r"   	Annotatedr4   __metadata__get_argsr   r0   r*   builtinslistSetOfbytesr   	BitString	IA5StringPrintableStringr-   TLVr+   r)   Implicitr(   r   r6   TypeSequenceSetAnnotatedTypecastr%   lenNoneTypetype_normalize_field_type
annotationis_emptyOption_type_to_variantr;   anyChoice
SequenceOfnon_root_python_to_rust)r#   r2   rU   _	root_type
union_argsoptional_typeannotated_typerust_field_typeargvariantsr=   tagsrust_choice_type
inner_typer>   s                  @r   rT   rT   j   sq   
 $(8(88()@)@*M
4
Q%002
"*%hmmU-CCNNLL

 j\ "* *
 	
 Sj))84* &H H  +* &G G 
 z?+,,	""++-=-B-B-F-FG
 5i[ABB--KK(--y9:
 	
 
:	__Z0
z?aH
$: ",A$t*!<
1*Q-  #*  3=*MN!,,557?  !!-! 
 /33::>JO *--x8!  &d4j( !j1H  &.a[%9%9%E" !   E 
 &,45q

55x=CI-#) 
  044;;HE z) !%%,,$22(*:*E*E*G &  
		:	&(--	7*OOJ'*J

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

 +//55jA*BB:N))/:FFg& 6s   > R+R0c                   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"]]`.r6   )r    r"   r@   rB   r   Literalr-   r   r6   r   r\   rO   r4   rA   r0   rT   )	tr2   is_annotatedrg   
value_typetag_literalr;   	rust_typeann_types	            r   rX   rX      sB    $$Q'6+;+;;L*6#A&AJ $/"(//*"=
K[)?; 
 ??;/2:/"00I(@@LI'55#ANNJ?H
 (55 ++-H
  ''8DD  ''!!Z0
 	
r   c                \    i }| j                         D ]  \  }}t        ||      }|||<    |S r:   )itemsrT   )
raw_fieldsfieldsr2   r#   annotated_field_types        r   _annotate_fieldsru   %  sF     F","2"2"4 2
J  5ZL1z	2 Mr   c                    t        j                  | d      }t        j                  j	                  | t        |            }t        | d|       y NT)include_extrasr6   )r    get_type_hintsr   rL   rM   ru   setattrclsrr   roots      r   _register_asn1_sequencer~   2  s>    &&s4@J  ))#/?
/KLDC$'r   c                    t        j                  | d      }t        j                  j	                  | t        |            }t        | d|       y rw   )r    ry   r   rL   rN   ru   rz   r{   s      r   _register_asn1_setr   9  s>    &&s4@J  $$S*::*F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   )sysversion_infodataclasses	dataclassr~   r|   dataclass_clss     r   sequencer   F  st     w&	K11 ! 	 	MK1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   ]  st     w&	K11 ! 	 	MK11 M 	=)r   c                Z     t        j                  dddd      |       }t        |       |S NFTr   )r   r   r~   r   s     r   r   r   v  s<    
--	

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

  	=)r   c                      e Zd ZU ded<   y)r,   r   r   N)r   r   r   r   r   r   r   r,   r,     s    Hr   r,   )r#   rS   returnbool)r1   tupler2   r   r   zdeclarative_asn1.Annotation)r#   
typing.Anyr2   r   r   zdeclarative_asn1.AnnotatedType)rj   r   r2   r   r   zdeclarative_asn1.Variant)rr   zdict[str, type]r   z)dict[str, declarative_asn1.AnnotatedType])r|   type[U]r   None)r|   r   r   r   )/
__future__r   rC   r   r   r   r    r   typing_extensionsLiteralString"cryptography.hazmat.bindings._rustr   rS   rR   TypeVarr	   r   r   r   Genericr   
decode_der
encode_derr%   r4   rT   rX   ru   r~   r   dataclass_transformr   r   r,   rE   r.   ExplicitrK   r/   rI   rH   UTCTimeGeneralizedTimerG   TlvrJ   Nullr   r   r   <module>r      s  
 #   
  g%33M((M ?gDzH~~HFNN3$'FNN3fnnU-0 d#fnnQV$  $, ((
((
	8  !$   FKGKG(+KG#KG`(
(
"(
(
V

.
(( g***4@ A, +**4@ A0  V5
 6
  V5
 6
 d#fnnQ  $ 	$$--$$--"22&&	

"
""22&&	r   