
    GjJ                    D   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKr\R                  S:  a  S SK	r	\	R                  r
O\R                  r
S SKJr  S SKJr  \R                  S:  a	  \" S5      rO\R                   r\R"                  " SSS	9r\R"                  " S
5      r\R"                  " S\
S9r\R*                  " SS9 " S S\R,                  \\4   5      5       r\R0                  r\R2                  r\R4                  \R6                  \R8                  4r        S!S jrS"S jrS#S jr       S$S jr!      S%S jr"      S&S jr#    S'S jr$S(S jr%S(S jr&\R                  S:  a1  \	RN                  " SS9S)S j5       r(\	RN                  " SS9S)S j5       r)O0\RN                  " SS9S)S j5       r(\RN                  " SS9S)S j5       r)    S*S jr*\R*                  " SS9 " S S \R,                  \   5      5       r+\RX                  r,\RZ                  R\                  r.\RZ                  R^                  r/\R`                  r0\Rb                  r1\Rd                  r2\Rf                  r3\Rh                  r4\Rj                  r5\Rl                  r7\Rp                  r8g)+    )annotationsN)      )declarative_asn1)x509r   
   TT)	covariantUTag)bound)frozenc                  .    \ rS rSr% SrS\S'   S\S'   Srg)	Variant"   a  
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tag N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       _/Users/admin/workspace/tools/venv/lib/python3.13/site-packages/cryptography/hazmat/asn1/asn1.pyr   r   "   s    " H	Hr   r   c                v    U [         ;   a/  [        UR                  [        5      (       a  [	        SU S35      eg g )Nfield 'zY' has an IMPLICIT annotation, but IMPLICIT annotations are not supported for X.509 types.)_X509_TYPES
isinstanceencodingImplicit	TypeError)
field_type
annotation
field_names      r   _check_x509_field_annotationsr*   D   sG    
 [ Z
0C0CX%N%Nj\ "F F
 	
 &O r   c                    [        [        S5      (       a   [        R                  [        R                  4O[        R                  4n[        R
                  " U 5      U;   $ )N	UnionType)hasattrtypesr,   typingUnion
get_origin)r'   union_typess     r   	_is_unionr3   P   sI     5+&& 
&,,'ll_ 
 Z(K77r   c                   [         R                  S:  a  U $ [        U [        R                  5      (       a-  U R
                  n [        U [        R                  5      (       a  M-  [        R                  " U 5      n[        S U 5       5      nX!:X  a  U $ [        U 5      (       a  [        R                  U   $ [        R                  " U 5      U   $ )N)r      c              3  8   #    U  H  n[        U5      v   M     g 7fN)_resolve_type_aliases).0args     r   	<genexpr>(_resolve_type_aliases.<locals>.<genexpr>i   s     E/44s   )sysversion_infor#   r/   TypeAliasType	__value__get_argstupler3   r0   r1   )r'   argsresolved_argss      r   r8   r8   \   s     '!
Z!5!5
6
6))
 Z!5!5
6
6 ??:&DEEEM ||M** Z(77r   c                   S nS nS nU  H  n[        U[        5      (       a   Ub  [        SU S35      eUR                  nM8  [        U[        R
                  5      (       a  Ub  [        SU S35      eUnMm  [        U[        R                  5      (       a  Ub  [        SU S35      eUnM  [        SU 35      e   [        R                  " X#US9$ )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)metadatar)   rG   r$   rH   raw_annotations         r   _extract_annotationrO      s    GHD"ng..""|1&  %**G(8(A(ABB#"|1&  &H(8(=(=>>@AN  "D6~6FGHH- #0 && r   c                
  ^ [        U 5      n [        R                  " U 5      [        R                  L a.  [	        U R
                  U5      n[        R                  " U 5      tpO[        R                  " 5       nUR                  bp  [        R                  " U 5      [        R                  [        4;  aB  U [        R                  [        R                  [        [         ["        4;  a  [%        SU S35      eU [&        L aJ  [)        UR*                  [,        5      (       a  [%        SU S35      eUR.                  b  [%        SU S35      e[1        XU5        [3        U S5      (       a  U R4                  n[)        U[        R6                  R8                  [        R6                  R:                  [        R6                  R<                  45      (       d  [%        SU 35      e[        R>                  " [        R@                  " [        R6                  U5      U5      $ [C        U 5      (       Ga  [        R                  " U 5      n[E        U5      S:X  a  [F        U;   a  US   [I        S 5      L a  US	   OUS   nU[&        L a  [%        S
5      e[1        XbU5        [K        Xa5      nURL                  RO                  5       (       d  [%        S5      eUR.                  b  [%        S5      e[        R6                  RQ                  U5      nGO#[)        UR*                  [,        5      (       a  [%        S5      eU V	s/ s H  n	U	[I        S 5      Ld  M  [S        X5      PM      n
n	U
S	   RT                  S Lm[W        U4S jU
 5       5      (       a  [%        S5      eT(       a>  U
 Vs1 s H  oRT                  iM     nn[E        U
5      [E        U5      :w  a  [%        S5      e[        R6                  RY                  U
5      n[F        U;   aG  [        R6                  RQ                  [        R>                  " U[        R                  " 5       5      5      OUnO[        R                  " U 5      [        R                  L aC  [K        [        R                  " U 5      S	   U5      n[        R6                  R[                  U5      nOv[        R                  " U 5      [        L aC  [K        [        R                  " U 5      S	   U5      n[        R6                  R                  U5      nO[        R\                  " U 5      n[        R>                  " X5      $ s  sn	f s  snf )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              3  F   >#    U  H  nUR                   S LT:g  v   M     g 7fr7   )tag_name)r9   vare_union_types_taggeds     r   r;   (_normalize_field_type.<locals>.<genexpr>  s'      !A 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)/r8   r/   r1   	AnnotatedrO   __metadata__rA   r   rL   rH   builtinslistSetOfbytesr   	BitString	IA5StringPrintableStringr&   TLVr#   r$   r%   rG   r*   r-   rQ   TypeSequenceSetValueSetAnnotatedTypecastr3   lenNoneTypetype_normalize_field_typer(   is_emptyOption_type_to_variantrU   anyChoice
SequenceOfnon_root_python_to_rust)r'   r)   r(   _	root_type
union_argsoptional_typeannotated_typerust_field_typer:   variantsrV   tagsrust_choice_type
inner_typerW   s                  @r   rl   rl      s    'z2J $(8(88()@)@*M
4
Q%002
"*%hmmU-CCNNLL

 j\ "* *
 	
 Sj))844* &H H  +* &G G 
 "**Ez?++,,	 %%.. %%)) %%..
 
 5i[ABB--KK(--y9:
 	
 
:		__Z0
z?aH
$: ",A$t*!<
1*Q-  #*  *: 3=MN!,,5577?  !!-! 
 /33::>JO *--x88!  &%Cd4j( 2 1%   &.a[%9%9%E" !    E 
 &,45Hq

H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   +T6T6T;c                .   [         R                  " U 5      [         R                  L nU(       a  [         R                  " U 5      S   OU n[         R                  " U5      [        L Ga  [         R                  " U5      u  pE[         R                  " U5      [         R
                  La  [        S5      e[         R                  " U5      S   n[        US5      (       a  UR                  nO[        R                  " U5      nU(       a,  [        R                  " U[        U R                  U5      5      nO*[        R                  " U[        R                  " 5       5      n[        R                  " [        X5      $ [        R                  " U[        X5      S 5      $ )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"]]`.rQ   )r/   r1   rY   rA   r   Literalr&   r-   rQ   r   rs   rg   rO   rZ   rL   rl   )	tr)   is_annotatedr}   
value_typetag_literalrU   	rust_typeann_types	            r   ro   ro   @  s?    $$Q'6+;+;;L*6#A&AJ $/"(//*"=
[)?; 
 ??;/2://"00I(@@LI'55#ANNJ?H
 (55 ++-H
  ''DD  ''!!0
 	
r   c                Z    0 nU R                  5        H  u  p#[        X25      nXAU'   M     U$ r7   )itemsrl   )
raw_fieldsfieldsr)   r'   annotated_field_types        r   _annotate_fieldsr   k  s;     F","2"2"4
  5ZL1z	 #5 Mr   c                    [         R                  " U SS9n[        R                  R	                  U [        U5      5      n[        U SU5        g NT)include_extrasrQ   )r/   get_type_hintsr   rc   rd   r   setattrclsr   roots      r   _register_asn1_sequencer   x  s>    &&s4@J  ))#/?
/KLDC$'r   c                    [         R                  " U SS9n[        R                  R	                  U [        U5      5      n[        U SU5        g r   )r/   r   r   rc   re   r   r   r   s      r   _register_asn1_setr     s>    &&s4@J  $$S*::*FGDC$'r   )kw_only_defaultc                    [         R                  S:  a  [        R                  " SSSSS9" U 5      nO[        R                  " SSS9" U 5      n[	        U5        U$ Nr   FTrepreq
match_argskw_only)r   r   )r=   r>   dataclasses	dataclassr   r   dataclass_clss     r   sequencer     sn     w&'11 ! 	 	M (11 M 	 .r   c                    [         R                  S:  a  [        R                  " SSSSS9" U 5      nO[        R                  " SSS9" U 5      n[	        U5        U$ r   )r=   r>   r   r   r   r   s     r   setr     sn     w&'11 ! 	 	M (11 M 	=)r   c                V    [         R                  " SSSSS9" U 5      n[        U5        U$ NFTr   )r   r   r   r   s     r   r   r     s:     $--	

  	 .r   c                V    [         R                  " SSSSS9" U 5      n[        U5        U$ r   )r   r   r   r   s     r   r   r     s:     $--	

  	=)r   c                H   ^ ^ [         R                  " T 5      mSUU 4S jjnU$ )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.
c                  > [        U [        R                  5      (       d  [        S5      e[	        U 5      nU(       d  [        SU R
                   S35      eU Hq  n[        UR                  T5      (       a  M   [        SUR                   SU R
                   STR
                   S[        UR                  5      R
                   S3	5      e   [        R                  " T[        R                  " 5       5      nU Vs0 s H  o"R                  U_M     nn[        R                  R                  XU5      n[        U S	U5        U $ s  snf )
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: 'rF   rQ   )
issubclassenumEnumr&   r\   r   r#   r   namerk   r   rg   rL   rc   rf   r   )r   membersmemberinner	value_mapr   r   r   s         r   	decoratorvalue_set.<locals>.decorator  s1   #tyy))J  s)cll^+JK  FfllJ77v{{m+;CLL> J"++, -V\\*334A7   !..'224

 9@@f\\6)	@$$--c)D_d+
	 As   <Er   type[U]returnr   )r   rs   )r   r   r   s   ` @r   	value_setr     s'     !88DI : r   c                       \ rS rSr% S\S'   Srg)rI   i  r   r   r   N)r   r   r   r   r   r   r   r   r   rI   rI     s    Hr   rI   )r'   
typing.Anyr(   declarative_asn1.Annotationr)   r   r   None)r'   rk   r   bool)r'   r   r   r   )rM   rB   r)   r   r   r   )r'   r   r)   r   r   zdeclarative_asn1.AnnotatedType)r   r   r)   r   r   zdeclarative_asn1.Variant)r   zdict[str, type]r   z)dict[str, declarative_asn1.AnnotatedType])r   r   r   r   r   )r   rk   r   z#typing.Callable[[type[U]], type[U]])9
__future__r   r[   r   r   r=   r.   r/   r>   typing_extensionsLiteralString"cryptography.hazmat.bindings._rustr   r   	rust_x509rk   rj   TypeVarr
   r   r   r   Genericr   
decode_der
encode_derCertificateCertificateSigningRequestCertificateRevocationListr"   r*   r3   r8   rO   rl   ro   r   r   r   dataclass_transformr   r   r   rI   r]   rJ   Explicitr%   rK   ra   r`   UTCTimeGeneralizedTimer_   Tlvrb   Nullr   r   r   <module>r      s  
 #    
  g%33M((M ? @gDzH~~H
NN3$'
NN3nnU-0 d#fnnQV$  $, ((
((
 ''''	
	
+	
 	
 
		
	8!8H  !$   FXGXG(+XG#XGz(
(
"(
(
V

.
(( g**4@ A, **4@ A0 5
 6
 5
 6
))()Z d#fnnQ  $ 	$$--$$--"22&&	

"
""22&&	r   