
    F/jJ                    R   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j0                  Zej2                  Zej4                  ej6                  ej8                  fZ	 	 	 	 	 	 	 	 d!dZd"d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	jN                  d      d)d       Z( e	jN                  d      d)d       Z)n4 ejN                  d      d)d       Z( ejN                  d      d)d       Z)	 	 	 	 d*dZ* ej*                  d       G d d ej,                  e                Z+ejX                  Z,ejZ                  j\                  Z.ejZ                  j^                  Z/ej`                  Z0ejb                  Z1ejd                  Z2ejf                  Z3ejh                  Z4ejj                  Z5ejl                  Z7ejp                  Z8y)+    )annotationsN)      )declarative_asn1)x509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__     [/var/www/html/maxservice/venv/lib/python3.12/site-packages/cryptography/hazmat/asn1/asn1.pyr   r   "   s    " H	Hr   r   c                h    | t         v r*t        |j                  t              rt	        d| d      y y )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   sD    
 [ Z
0C0CX%Nj\ "F F
 	
 &O 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)r$   union_typess     r   	_is_unionr0   P   sF     5+& 
&,,'ll_ 
 Z(K77r   c                v   t         j                  dk  r| S t        | t        j                        r'| j
                  } t        | t        j                        r't        j                  |       }t        d |D              }||k(  r| S t        |       rt        j                  |   S t        j                  |       |   S )N)r      c              3  2   K   | ]  }t        |        y wN)_resolve_type_aliases).0args     r   	<genexpr>z(_resolve_type_aliases.<locals>.<genexpr>i   s     E/4Es   )sysversion_infor    r,   TypeAliasType	__value__get_argstupler0   r-   r.   )r$   argsresolved_argss      r   r5   r5   \   s     '!
Z!5!5
6))
 Z!5!5
6 ??:&DEEEM ||M** Z(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: )defaultr!   size)r    Defaultr#   r   r   EncodingSize
Annotation)metadatar&   rC   r!   rD   raw_annotations         r   _extract_annotationrK      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                	   t        |       } 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      t1        | ||       t3        | d      r| j4                  }t)        |t        j6                  j8                  t        j6                  j:                  t        j6                  j<                  f      st%        d|       t        j>                  t        j@                  t        j6                  |      |      S tC        |       rt        j                  |       }tE        |      dk(  rtF        |v r|d   tI        d       u r|d	   n|d   }|t&        u rt%        d
      t1        |||       tK        ||      }|jL                  jO                         st%        d      |j.                  t%        d      t        j6                  jQ                  |      }n t)        |j*                  t,              rt%        d      |D 	cg c]  }	|	tI        d       urtS        |	|       }
}	|
d	   jT                  d utW        fd|
D              rt%        d      r;|
D ch c]  }|jT                   }}tE        |
      tE        |      k7  rt%        d      t        j6                  jY                  |
      }tF        |v rEt        j6                  jQ                  t        j>                  |t        j                                     n|}nt        j                  |       t        j                  u rBtK        t        j                  |       d	   |      }t        j6                  j[                  |      }nrt        j                  |       t        u rBtK        t        j                  |       d	   |      }t        j6                  j                  |      }nt        j\                  |       }t        j>                  ||      S c c}	w c c}w )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  @   K   | ]  }|j                   d uk7    y wr4   )tag_name)r6   vare_union_types_taggeds     r   r8   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)/r5   r,   r.   	AnnotatedrK   __metadata__r=   r   rH   rD   builtinslistSetOfbytesr   	BitString	IA5StringPrintableStringr#   TLVr    r!   r"   rC   r'   r*   rM   TypeSequenceSetValueSetAnnotatedTypecastr0   lenNoneTypetype_normalize_field_typer%   is_emptyOption_type_to_variantrQ   anyChoice
SequenceOfnon_root_python_to_rust)r$   r&   r%   _	root_type
union_argsoptional_typeannotated_typerust_field_typer7   variantsrR   tagsrust_choice_type
inner_typerS   s                  @r   rg   rg      s    'z2J $(8(88()@)@*M
4
Q%002
"*%hmmU-CCNNLL

 j\ "* *
 	
 Sj))84* &H H  +* &G G 
 "*j*Ez?+,,	 %%.. %%)) %%..
 5i[ABB--KK(--y9:
 	
 
:	__Z0
z?aH
$: ",A$t*!<
1*Q-  #*  *z: 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   < S)S.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"]]`.rM   )r,   r.   rT   r=   r   Literalr#   r*   rM   r   rn   rb   rK   rU   rH   rg   )	tr&   is_annotatedrx   
value_typetag_literalrQ   	rust_typeann_types	            r   rj   rj   @  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 r4   )itemsrg   )
raw_fieldsfieldsr&   r$   annotated_field_types        r   _annotate_fieldsr   k  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_extrasrM   )r,   get_type_hintsr   r^   r_   r   setattrclsr   roots      r   _register_asn1_sequencer   x  s>    &&s4@J  ))#/?
/KLDC$'r   c                    t        j                  | d      }t        j                  j	                  | t        |            }t        | d|       y r   )r,   r   r   r^   r`   r   r   r   s      r   _register_asn1_setr     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   )r9   r:   dataclasses	dataclassr   r   dataclass_clss     r   sequencer     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   )r9   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     s<    
--	

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

  	=)r   c                B     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.
    c                h   t        | t        j                        st        d      t	        |       }|st        d| j
                   d      |D ]k  }t        |j                        rt        d|j                   d| j
                   dj
                   dt        |j                        j
                   d	       t        j                  t        j                               }|D ci c]  }|j                  | }}t        j                  j                  | ||      }t        | d	|       | S c c}w )
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   rM   )
issubclassenumEnumr#   rW   r   r    r   namerf   r   rb   rH   r^   ra   r   )r   membersmemberinner	value_mapr   r   r}   s         r   	decoratorzvalue_set.<locals>.decorator  s3   #tyy)J  s)cll^+JK   	FfllJ7v{{m+;CLL> J"++, -V\\*334A7 	 !..'224

 9@@fV\\6)@	@$$--c5)D_d+
	 As   )D/r   type[U]returnr   )r   rn   )r}   r   r   s   ` @r   	value_setr     s"     !88DI: r   c                      e Zd ZU ded<   y)rE   r   r   N)r   r   r   r   r   r   r   rE   rE     s    Hr   rE   )r$   
typing.Anyr%   declarative_asn1.Annotationr&   r   r   None)r$   rf   r   bool)r$   r   r   r   )rI   r>   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}   rf   r   z#typing.Callable[[type[U]], type[U]])9
__future__r   rV   r   r   r9   r+   r,   r:   typing_extensionsLiteralString"cryptography.hazmat.bindings._rustr   r   	rust_x509rf   re   TypeVarr
   r   r   r   Genericr   
decode_der
encode_derCertificateCertificateSigningRequestCertificateRevocationListr   r'   r0   r5   rK   rg   rj   r   r   r   dataclass_transformr   r   r   rE   rX   rF   Explicitr"   rG   r\   r[   UTCTimeGeneralizedTimerZ   Tlvr]   Nullr   r   r   <module>r      s'  
 #    
  g%33M((M ? @gDzH~~HFNN3$'FNN3fnnU-0 d#fnnQV$  $, ((
((
 ''''	
	
+	
 	
 
		
	8!8H  !$   FXGXG(+XG#XGz(
(
"(
(
V

.
(( g***4@ A, +**4@ A0  V5
 6
  V5
 6
))()Z d#fnnQ  $ 	$$--$$--"22&&	

"
""22&&	r   