
    ,d:                       U 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mZ d dl	m
Z d dlmZmZ  G d dej                  Zd eD             Zej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        iZd	ed
<   ej        eef         Zej        eef         Zej         dej!        dej"        dej#        dej$        dej        dej%        dej        dej&        di	Z'ded<   d e'(                                D             Z)d%dZ*d&dZ+ G d d          Z, G d d           Z- G d! d"          Z. G d# d$          Z/dS )'    )annotationsN)utils)x509)NameOIDObjectIdentifierc                  >    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdS )	_ASN1Type                                    N)__name__
__module____qualname__	BitStringOctetString
UTF8StringNumericStringPrintableString	T61String	IA5StringUTCTimeGeneralizedTimeVisibleStringUniversalString	BMPString     6lib/python3.11/site-packages/cryptography/x509/name.pyr	   r	      sJ        IKJMOIIGOMOIIIr&   r	   c                    i | ]
}|j         |S r%   )value).0is     r'   
<dictcomp>r,   !   s    444Qagq444r&   z(typing.Dict[ObjectIdentifier, _ASN1Type]_NAMEOID_DEFAULT_TYPECNLSTOOUCSTREETDCUID_OidNameMap_NAMEOID_TO_NAMEc                    i | ]\  }}||	S r%   r%   )r*   kvs      r'   r,   r,   <   s    >>>TQAq>>>r&   valtyping.Union[str, bytes]returnstrc                <   | sdS t          | t                    r*dt          j        |                               d          z   S |                     dd          } |                     dd          } |                     dd	          } |                     d
d          } |                     dd          } |                     dd          } |                     dd          } |                     dd          } | d         dv rd| z   } | d         dk    r| dd         dz   } | S )z>Escape special characters in RFC4514 Distinguished Name value. #utf8\z\\"z\"+z\+,z\,;z\;<z\<>z\> z\00r   )rB    rL   Nz\ )
isinstancebytesbinasciihexlifydecodereplace)r<   s    r'   _escape_dn_valuerT   ?   s     r #u :X%c**11&9999 ++dF
#
#C
++c5
!
!C
++c5
!
!C
++c5
!
!C
++c5
!
!C
++c5
!
!C
++c5
!
!C
++dF
#
#C
1vSj
2w#~~#2#hJr&   c                P    | sdS d }t           j                            ||           S )NrA   c                    |                      d          }t          |          dk    r|S t          t          |d                    S )N      )grouplenchrint)mr<   s     r'   subz_unescape_dn_value.<locals>.subd   s;    ggajjs88q==J3sB<<   r&   )_RFC4514NameParser_PAIR_REr^   )r<   r^   s     r'   _unescape_dn_valuera   \   s9     r! ! ! &**3444r&   c                      e Zd Z	 dddddZedd            Zedd            Zed d            Z	 dd!dZd"dZ	d#dZ
d dZdS )$NameAttributeNT)	_validateoidr   r)   r=   _typetyping.Optional[_ASN1Type]rd   boolr>   Nonec               @   t          |t                    st          d          |t          j        k    rD|t
          j        k    rt          d          t          |t                    st          d          n$t          |t                    st          d          |t
          j	        k    s|t
          j
        k    rt          |t                    sJ t          |                    d                    }|dk    r|du rt          d          |dk    r)t          j        d	                    |          d
           |%t"                              |t          j                  }t          |t                    st          d          || _        || _        || _        d S )Nz2oid argument must be an ObjectIdentifier instance.z6oid must be X500_UNIQUE_IDENTIFIER for BitString type.z!value must be bytes for BitStringzvalue argument must be a strrC      Tz/Country name must be a 2 character country codezUCountry names should be two characters, but the attribute is {} characters in length.)
stacklevelz%_type must be from the _ASN1Type enum)rN   r   	TypeErrorr	   r   r   X500_UNIQUE_IDENTIFIERrO   r?   COUNTRY_NAMEJURISDICTION_COUNTRY_NAMErZ   encode
ValueErrorwarningswarnformatr-   getr   _oid_valuerf   )selfre   r)   rf   rd   c_lens         r'   __init__zNameAttribute.__init__p   s    #/00 	D   I'''g444L   eU++ E CDDDE eS)) @ >??? 7'''g777eS)))))V,,--Ezzi4// E   !<<BF5MM     =)--c93GHHE%++ 	ECDDD	


r&   c                    | j         S N)rw   ry   s    r'   re   zNameAttribute.oid   s
    yr&   c                    | j         S r}   )rx   r~   s    r'   r)   zNameAttribute.value   s
    {r&   r?   c                V    t                               | j        | j        j                  S )zt
        The short attribute name (for example "CN") if available,
        otherwise the OID dotted string.
        )r8   rv   re   dotted_stringr~   s    r'   rfc4514_attribute_namez$NameAttribute.rfc4514_attribute_name   s!      ##DHdh.DEEEr&   attr_name_overridestyping.Optional[_OidNameMap]c                    |r|                     | j                  nd}|| j        }| dt          | j                   S )z
        Format as RFC4514 Distinguished Name string.

        Use short attribute name if available, otherwise fall back to OID
        dotted string.
        N=)rv   re   r   rT   r)   )ry   r   	attr_names      r'   rfc4514_stringzNameAttribute.rfc4514_string   sW     2EN##DH---$ 	 3I<<.tz::<<<r&   otherobjectc                z    t          |t                    st          S | j        |j        k    o| j        |j        k    S r}   )rN   rc   NotImplementedre   r)   ry   r   s     r'   __eq__zNameAttribute.__eq__   s7    %// 	"!!x59$Bu{)BBr&   r\   c                8    t          | j        | j        f          S r}   )hashre   r)   r~   s    r'   __hash__zNameAttribute.__hash__   s    TXtz*+++r&   c                ,    d                     |           S )Nz/<NameAttribute(oid={0.oid}, value={0.value!r})>)ru   r~   s    r'   __repr__zNameAttribute.__repr__   s    @GGMMMr&   r}   )
re   r   r)   r=   rf   rg   rd   rh   r>   ri   )r>   r   )r>   r=   r>   r?   r   r   r>   r?   r   r   r>   rh   r>   r\   )r   r   r   r{   propertyre   r)   r   r   r   r   r   r%   r&   r'   rc   rc   o   s       
 -1	6 6 6 6 6 6 6p    X    X F F F XF CG= = = = ="C C C C, , , ,N N N N N Nr&   rc   c                  R    e Zd ZddZddZ	 dddZddZddZddZddZ	ddZ
d	S ) RelativeDistinguishedName
attributestyping.Iterable[NameAttribute]c                4   t          |          }|st          d          t          d |D                       st          d          || _        t          |          | _        t          | j                  t          |          k    rt          d          d S )Nz-a relative distinguished name cannot be emptyc              3  @   K   | ]}t          |t                    V  d S r}   rN   rc   r*   xs     r'   	<genexpr>z5RelativeDistinguishedName.__init__.<locals>.<genexpr>   s,      DDA:a//DDDDDDr&   z/attributes must be an iterable of NameAttributez$duplicate attributes are not allowed)listrr   allrm   _attributes	frozenset_attribute_setrZ   ry   r   s     r'   r{   z"RelativeDistinguishedName.__init__   s    *%%
 	NLMMMDDDDDDD 	OMNNN &'
33t"##s:66CDDD 76r&   re   r   r>   typing.List[NameAttribute]c                     fd| D             S )Nc                *    g | ]}|j         k    |S r%   re   r*   r+   re   s     r'   
<listcomp>zDRelativeDistinguishedName.get_attributes_for_oid.<locals>.<listcomp>        000a15C<<<<<r&   r%   ry   re   s    `r'   get_attributes_for_oidz0RelativeDistinguishedName.get_attributes_for_oid        100040000r&   Nr   r   r?   c                P    d                     fd| j        D                       S )z
        Format as RFC4514 Distinguished Name string.

        Within each RDN, attributes are joined by '+', although that is rarely
        used in certificates.
        rF   c              3  B   K   | ]}|                               V  d S r}   r   r*   attrr   s     r'   r   z;RelativeDistinguishedName.rfc4514_string.<locals>.<genexpr>   F       
 
  344
 
 
 
 
 
r&   joinr   ry   r   s    `r'   r   z(RelativeDistinguishedName.rfc4514_string   sD     xx 
 
 
 
(
 
 
 
 
 	
r&   r   r   rh   c                Z    t          |t                    st          S | j        |j        k    S r}   )rN   r   r   r   r   s     r'   r   z RelativeDistinguishedName.__eq__   s,    %!:;; 	"!!"e&:::r&   r\   c                *    t          | j                  S r}   )r   r   r~   s    r'   r   z"RelativeDistinguishedName.__hash__   s    D'(((r&   typing.Iterator[NameAttribute]c                *    t          | j                  S r}   )iterr   r~   s    r'   __iter__z"RelativeDistinguishedName.__iter__  s    D$%%%r&   c                *    t          | j                  S r}   )rZ   r   r~   s    r'   __len__z!RelativeDistinguishedName.__len__  s    4#$$$r&   c                2    d|                                   dS )Nz<RelativeDistinguishedName()>r   r~   s    r'   r   z"RelativeDistinguishedName.__repr__  s    FT-@-@-B-BFFFFr&   )r   r   re   r   r>   r   r}   r   r   r   r>   r   r   )r   r   r   r{   r   r   r   r   r   r   r   r%   r&   r'   r   r      s        E E E E1 1 1 1 CG
 
 
 
 
; ; ; ;) ) ) )& & & &% % % %G G G G G Gr&   r   c                      e Zd Zej        d&d            Zej        d'd            Zd(d	Ze	 d)d*d            Z	 d)d+dZd,dZ	e
d-d            Zd)d.dZd/dZd0d!Zd1d#Zd0d$Zd2d%Zd
S )3Namer   r   r>   ri   c                    d S r}   r%   r   s     r'   r{   zName.__init__  s    r&   *typing.Iterable[RelativeDistinguishedName]c                    d S r}   r%   r   s     r'   r{   zName.__init__  s	     	r&   Gtyping.Iterable[typing.Union[NameAttribute, RelativeDistinguishedName]]c                *   t          |          }t          d |D                       rd |D             | _        d S t          d |D                       r1t          j        t          j        t                   |          | _        d S t          d          )Nc              3  @   K   | ]}t          |t                    V  d S r}   r   r   s     r'   r   z Name.__init__.<locals>.<genexpr>  s,      @@z!]++@@@@@@r&   c                ^    g | ]*}t          t          j        t          |          g          +S r%   )r   typingcastrc   r   s     r'   r   z!Name.__init__.<locals>.<listcomp>  s?           *6;}a+H+H*IJJ     r&   c              3  @   K   | ]}t          |t                    V  d S r}   )rN   r   r   s     r'   r   z Name.__init__.<locals>.<genexpr>"  s-      NNaA899NNNNNNr&   zNattributes must be a list of NameAttribute or a list RelativeDistinguishedName)r   r   r   r   r   Listr   rm   r   s     r'   r{   zName.__init__  s     *%%
@@Z@@@@@ 	   #     D NN:NNNNN 	%{56
   D 7  r&   Ndatar?   r   typing.Optional[_NameOidMap]c                J    t          ||pi                                           S r}   )r_   parse)clsr   r   s      r'   from_rfc4514_stringzName.from_rfc4514_string,  s&     "$(;(ArBBHHJJJr&   r   c                j    d                     fdt          | j                  D                       S )a  
        Format as RFC4514 Distinguished Name string.
        For example 'CN=foobar.com,O=Foo Corp,C=US'

        An X.509 name is a two-level structure: a list of sets of attributes.
        Each list element is separated by ',' and within each list element, set
        elements are separated by '+'. The latter is almost never used in
        real world certificates. According to RFC4514 section 2.1 the
        RDNSequence must be reversed when converting to string representation.
        rG   c              3  B   K   | ]}|                               V  d S r}   r   r   s     r'   r   z&Name.rfc4514_string.<locals>.<genexpr>A  r   r&   )r   reversedr   r   s    `r'   r   zName.rfc4514_string4  sL     xx 
 
 
 
 !122
 
 
 
 
 	
r&   re   r   r   c                     fd| D             S )Nc                *    g | ]}|j         k    |S r%   r   r   s     r'   r   z/Name.get_attributes_for_oid.<locals>.<listcomp>I  r   r&   r%   r   s    `r'   r   zName.get_attributes_for_oidF  r   r&   &typing.List[RelativeDistinguishedName]c                    | j         S r}   r   r~   s    r'   rdnsz	Name.rdnsK  s    r&   backend
typing.AnyrO   c                *    t          j        |           S r}   )	rust_x509encode_name_bytes)ry   r   s     r'   public_byteszName.public_bytesO  s    *4000r&   r   r   rh   c                Z    t          |t                    st          S | j        |j        k    S r}   )rN   r   r   r   r   s     r'   r   zName.__eq__R  s+    %&& 	"!!5#444r&   r\   c                D    t          t          | j                            S r}   )r   tupler   r~   s    r'   r   zName.__hash__X  s     E$*++,,,r&   r   c              #  0   K   | j         D ]}|D ]}|V  d S r}   r   )ry   rdnavas      r'   r   zName.__iter__]  sA      # 	 	C  					 	r&   c                >    t          d | j        D                       S )Nc              3  4   K   | ]}t          |          V  d S r}   )rZ   )r*   r   s     r'   r   zName.__len__.<locals>.<genexpr>c  s(      883s88888888r&   )sumr   r~   s    r'   r   zName.__len__b  s"    88t'7888888r&   c                V    d                     d | j        D                       }d| dS )NrG   c              3  >   K   | ]}|                                 V  d S r}   r   )r*   r   s     r'   r   z Name.__repr__.<locals>.<genexpr>f  s.      KK$++--KKKKKKr&   z<Name(r   r   ry   r   s     r'   r   zName.__repr__e  s6    xxKK$:JKKKKK     r&   )r   r   r>   ri   )r   r   r>   ri   )r   r   r>   ri   r}   )r   r?   r   r   r>   r   r   r   )r>   r   )r   r   r>   rO   r   r   r   r   )r   r   r   r   overloadr{   classmethodr   r   r   r   r   r   r   r   r   r   r   r%   r&   r'   r   r     sk       _   _ _   _
   ,  =AK K K K [K CG
 
 
 
 
$1 1 1 1
       X 1 1 1 1 15 5 5 5- - - -
   
9 9 9 9! ! ! ! ! !r&   r   c                     e Zd Z ej        d          Z ej        d          ZdZ ej        e          ZdZ	dZ
dZd eej                   dZe	 d	e Ze
 d	e Ze d	e Z ej        d
e d	e de d	e de d	e dej                  Z ej        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d#S ),r_   z!(0|([1-9]\d*))(\.(0|([1-9]\d*)))+z[a-zA-Z][a-zA-Z\d-]*z!\\([\\ #=\"\+,;<>]|[\da-zA-Z]{2})z7[\x01-\x1f\x21\x24-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z3[\x01-\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z7[\x01-\x1F\x21\x23-\x2A\x2D-\x3A\x3D\x3F-\x5B\x5D-\x7F]z[\x80-]|z
        (
            (z!)
            (
                (z)*
                (z$)
            )?
        )?
        z#([\da-zA-Z]{2})+r   r?   r   _NameOidMapr>   ri   c                0    || _         d| _        || _        d S )Nr   )_data_idx_attr_name_overrides)ry   r   r   s      r'   r{   z_RFC4514NameParser.__init__  s    
	$7!!!r&   rh   c                <    | j         t          | j                  k     S r}   )r   rZ   r   r~   s    r'   	_has_dataz_RFC4514NameParser._has_data  s    y3tz??**r&   typing.Optional[str]c                R    |                                  r| j        | j                 S d S r}   )r  r   r   r~   s    r'   _peekz_RFC4514NameParser._peek  s(    >> 	):di((tr&   chc                d    |                                  |k    rt          | xj        dz  c_        d S )NrW   )r  rr   r   )ry   r  s     r'   
_read_charz_RFC4514NameParser._read_char  s.    ::<<2		Q				r&   c                    |                     | j        | j                  }|t          |                                }| xj        t          |          z  c_        |S )N)pos)matchr   r   rr   rY   rZ   )ry   patr
  r<   s       r'   _read_rez_RFC4514NameParser._read_re  sN    		$*$)	44=kkmm		SXX		
r&   r   c                ,   |                                  g}|                                 rP|                     d           |                    |                                             |                                 Pt	          t          |                    S )a'  
        Parses the `data` string and converts it to a Name.

        According to RFC4514 section 2.1 the RDNSequence must be
        reversed when converting to string representation. So, when
        we parse it, we need to reverse again to get the RDNs on the
        correct order.
        rG   )
_parse_rdnr  r  appendr   r   r   s     r'   r   z_RFC4514NameParser.parse  s     !!"nn 	+OOC   KK))*** nn 	+ HTNN###r&   r   c                "   |                                  g}|                                 dk    rT|                     d           |                    |                                             |                                 dk    Tt	          |          S )NrF   )	_parse_nar  r  r  r   )ry   nass     r'   r  z_RFC4514NameParser._parse_rdn  sz    ~~ jjllc!!OOC   JJt~~''((( jjllc!! )---r&   rc   c                   	 |                      | j                  }t          |          }nf# t          $ rY |                      | j                  }| j                            |t                              |                    }|t          Y nw xY w|                     d           | 	                                dk    rI|                      | j
                  }t          j        |dd                                                    }n)|                      | j                  }t          |          }t!          ||          S )Nr   rB   rW   )r  _OID_REr   rr   	_DESCR_REr   rv   _NAME_TO_NAMEOIDr  r  _HEXSTRING_RErP   	unhexlifyrR   
_STRING_REra   rc   )ry   	oid_valuere   namer)   	raw_values         r'   r  z_RFC4514NameParser._parse_na  s,   
	.dl33I #9--CC  	! 	! 	!==00D+//&**400 C {   {	! 	::<<3MM$"455E&uQRRy1188::EEdo66I&y11ES%(((s   , A BBN)r   r?   r   r   r>   ri   )r>   rh   )r>   r  )r  r?   r>   ri   r   )r>   r   )r>   r   )r>   rc   )r   r   r   recompiler  r  _PAIRr`   _LUTF1_SUTF1_TUTF1r[   sys
maxunicode_UTFMB	_LEADCHAR_STRINGCHAR
_TRAILCHARVERBOSEr  r  r{   r  r  r  r  r   r  r  r%   r&   r'   r_   r_   j  s       bj=>>G
233I0Erz%  HGFCFGF-ss3>**---F%%V%%I''v''K&&f&&J		 		 	 		 	 !&		 	
 	 	
  %	 	 	 	
 J BJ344M8 8 8 8+ + + +   
   
   $ $ $ $". . . .) ) ) ) ) )r&   r_   )r<   r=   r>   r?   )r<   r?   r>   r?   )0
__future__r   rP   r  r#  r   rs   cryptographyr   "cryptography.hazmat.bindings._rustr   r   cryptography.x509.oidr   r   Enumr	   _ASN1_TYPE_TO_ENUMro   r   rp   SERIAL_NUMBERDN_QUALIFIEREMAIL_ADDRESSr   DOMAIN_COMPONENTr-   __annotations__Mappingr?   r7   r   COMMON_NAMELOCALITY_NAMESTATE_OR_PROVINCE_NAMEORGANIZATION_NAMEORGANIZATIONAL_UNIT_NAMESTREET_ADDRESSUSER_IDr8   itemsr  rT   ra   rc   r   r   r_   r%   r&   r'   <module>r>     s  
 # " " " " " "  				 



         @ @ @ @ @ @ ; ; ; ; ; ; ; ;    
    54)444 )3%y'@94)39.i1C      n-s23nS"223
 3"Ds$d#HdOU
!  
 
 
 
 ?>%5%;%;%=%=>>>    :5 5 5 5&dN dN dN dN dN dN dN dNN2G 2G 2G 2G 2G 2G 2G 2Gj\! \! \! \! \! \! \! \!~d) d) d) d) d) d) d) d) d) d)r&   