o
    )%a                  
   @   s   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 d dl	m
Z
 dddd	d
ddddd	ZG dd deZG dd de jdZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZdS )#    N)	parseaddr)utils)Name)ObjectIdentifierZ	otherNameZ
rfc822NameZdNSNameZx400AddressZdirectoryNameZediPartyNameZuniformResourceIdentifierZ	iPAddressZregisteredID)	r                           c                       s   e Zd Z fddZ  ZS )UnsupportedGeneralNameTypec                    s   t t| | || _d S N)superr   __init__type)selfmsgr   	__class__ @/usr/lib/python3/dist-packages/cryptography/x509/general_name.pyr      s   
z#UnsupportedGeneralNameType.__init__)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s    r   c                   @   s   e Zd Zejdd ZdS )GeneralNamec                 C   s   dS )z0
        Return the value of the object
        Nr   r   r   r   r   value$   s    zGeneralName.valueN)r   r   r   abcabstractpropertyr   r   r   r   r   r   #   s    r   )	metaclassc                   @   p   e Zd ZdefddZedZedd Z	defdd	Z
d
edefddZd
edefddZdefddZdS )
RFC822Namer   c                 C   s^   t |trz|d W n ty   tdw tdt|\}}|s&|s*td|| _d S )NasciizRFC822Name values should be passed as an A-label string. This means unicode characters should be encoded via a library like idna.value must be stringzInvalid rfc822name value)
isinstancestrencodeUnicodeEncodeError
ValueError	TypeErrorr   _value)r   r   nameZaddressr   r   r   r   ,   s   

zRFC822Name.__init__r-   c                 C      |  | }||_|S r   __new__r-   clsr   instancer   r   r   _init_without_validationC      
z#RFC822Name._init_without_validationreturnc                 C      d | jS )Nz<RFC822Name(value={0!r})>formatr   r   r   r   r   __repr__I      zRFC822Name.__repr__otherc                 C      t |tstS | j|jkS r   )r'   r$   NotImplementedr   r   r=   r   r   r   __eq__L      
zRFC822Name.__eq__c                 C   
   | |k S r   r   r@   r   r   r   __ne__R      
zRFC822Name.__ne__c                 C   
   t | jS r   hashr   r   r   r   r   __hash__U   rE   zRFC822Name.__hash__Nr   r   r   r(   r   r   read_only_propertyr   classmethodr5   r;   objectboolrA   rD   intrI   r   r   r   r   r$   +   s    

r$   c                   @   sj   e Zd ZdefddZedZedd Z	dd Z
d	ed
efddZd	ed
efddZd
efddZdS )DNSNamer   c                 C   B   t |trz|d W n ty   tdw td|| _d S )Nr%   z~DNSName values should be passed as an A-label string. This means unicode characters should be encoded via a library like idna.r&   r'   r(   r)   r*   r+   r,   r-   r   r   r   r   r   r   Z      

zDNSName.__init__r-   c                 C   r/   r   r0   r2   r   r   r   r5   k   r6   z DNSName._init_without_validationc                 C   r8   )Nz<DNSName(value={0!r})>r9   r   r   r   r   r;   q   r<   zDNSName.__repr__r=   r7   c                 C   r>   r   )r'   rP   r?   r   r@   r   r   r   rA   t   rB   zDNSName.__eq__c                 C   rC   r   r   r@   r   r   r   rD   z   rE   zDNSName.__ne__c                 C   rF   r   rG   r   r   r   r   rI   }   rE   zDNSName.__hash__NrJ   r   r   r   r   rP   Y   s    

rP   c                   @   r#   )UniformResourceIdentifierr   c                 C   rQ   )Nr%   zzURI values should be passed as an A-label string. This means unicode characters should be encoded via a library like idna.r&   rR   rS   r   r   r   r      rT   z"UniformResourceIdentifier.__init__r-   c                 C   r/   r   r0   r2   r   r   r   r5      r6   z2UniformResourceIdentifier._init_without_validationr7   c                 C   r8   )Nz(<UniformResourceIdentifier(value={0!r})>r9   r   r   r   r   r;      r<   z"UniformResourceIdentifier.__repr__r=   c                 C   r>   r   )r'   rU   r?   r   r@   r   r   r   rA      rB   z UniformResourceIdentifier.__eq__c                 C   rC   r   r   r@   r   r   r   rD      rE   z UniformResourceIdentifier.__ne__c                 C   rF   r   rG   r   r   r   r   rI      rE   z"UniformResourceIdentifier.__hash__NrJ   r   r   r   r   rU      s    

rU   c                   @   d   e Zd ZdefddZedZdefddZ	de
defd	d
Zde
defddZdefddZdS )DirectoryNamer   c                 C      t |ts	td|| _d S )Nzvalue must be a Name)r'   r   r,   r-   rS   r   r   r   r         

zDirectoryName.__init__r-   r7   c                 C   r8   )Nz<DirectoryName(value={})>r9   r   r   r   r   r;      r<   zDirectoryName.__repr__r=   c                 C   r>   r   )r'   rW   r?   r   r@   r   r   r   rA      rB   zDirectoryName.__eq__c                 C   rC   r   r   r@   r   r   r   rD      rE   zDirectoryName.__ne__c                 C   rF   r   rG   r   r   r   r   rI      rE   zDirectoryName.__hash__N)r   r   r   r   r   r   rK   r   r(   r;   rM   rN   rA   rD   rO   rI   r   r   r   r   rW          
rW   c                   @   rV   )RegisteredIDr   c                 C   rX   )Nz!value must be an ObjectIdentifier)r'   r   r,   r-   rS   r   r   r   r      rY   zRegisteredID.__init__r-   r7   c                 C   r8   )Nz<RegisteredID(value={})>r9   r   r   r   r   r;      r<   zRegisteredID.__repr__r=   c                 C   r>   r   )r'   r[   r?   r   r@   r   r   r   rA      rB   zRegisteredID.__eq__c                 C   rC   r   r   r@   r   r   r   rD      rE   zRegisteredID.__ne__c                 C   rF   r   rG   r   r   r   r   rI      rE   zRegisteredID.__hash__N)r   r   r   r   r   r   rK   r   r(   r;   rM   rN   rA   rD   rO   rI   r   r   r   r   r[      rZ   r[   c                   @   sz   e Zd Zdejejejejej	f fddZ
edZdefddZdedefd	d
ZdedefddZdefddZdS )	IPAddressr   c                 C   s,   t |tjtjtjtjfstd|| _d S )Nzzvalue must be an instance of ipaddress.IPv4Address, ipaddress.IPv6Address, ipaddress.IPv4Network, or ipaddress.IPv6Network)r'   	ipaddressIPv4AddressIPv6AddressIPv4NetworkIPv6Networkr,   r-   rS   r   r   r   r      s   		
zIPAddress.__init__r-   r7   c                 C   r8   )Nz<IPAddress(value={})>r9   r   r   r   r   r;      r<   zIPAddress.__repr__r=   c                 C   r>   r   )r'   r\   r?   r   r@   r   r   r   rA      rB   zIPAddress.__eq__c                 C   rC   r   r   r@   r   r   r   rD     rE   zIPAddress.__ne__c                 C   rF   r   rG   r   r   r   r   rI     rE   zIPAddress.__hash__N)r   r   r   typingZUnionr]   r^   r_   r`   ra   r   r   rK   r   r(   r;   rM   rN   rA   rD   rO   rI   r   r   r   r   r\      s    

r\   c                   @   sr   e Zd ZdedefddZedZedZ	de
fdd	Zd
edefddZd
edefddZdefddZdS )	OtherNametype_idr   c                 C   s4   t |ts	tdt |tstd|| _|| _d S )Nz#type_id must be an ObjectIdentifierzvalue must be a binary string)r'   r   r,   bytes_type_idr-   )r   rd   r   r   r   r   r   	  s   


zOtherName.__init__rf   r-   r7   c                 C   s   d | j| jS )Nz#<OtherName(type_id={}, value={!r})>)r:   rd   r   r   r   r   r   r;     s   zOtherName.__repr__r=   c                 C   s&   t |tstS | j|jko| j|jkS r   )r'   rc   r?   rd   r   r@   r   r   r   rA     s   
zOtherName.__eq__c                 C   rC   r   r   r@   r   r   r   rD      rE   zOtherName.__ne__c                 C   s   t | j| jfS r   )rH   rd   r   r   r   r   r   rI   #  s   zOtherName.__hash__N)r   r   r   r   re   r   r   rK   rd   r   r(   r;   rM   rN   rA   rD   rO   rI   r   r   r   r   rc     s    
	
rc   )r    r]   rb   Zemail.utilsr   Zcryptographyr   Zcryptography.x509.namer   Zcryptography.x509.oidr   Z_GENERAL_NAMES	Exceptionr   ABCMetar   r$   rP   rU   rW   r[   r\   rc   r   r   r   r   <module>   s4   .((-