U
    ;g
                     @   sB   d dl mZ d dlmZ d dlmZ d dlmZ G dd dZdS )    )Optional)x509ValidationPath)ConsListc                   @   sf   e Zd Zdddee ee edddZe	dd Z
e	ed	d
dZejdddZdddZdS )ValProcStateNF)ee_name_overrideis_side_validation)cert_path_stackr   r	   c                C   s8   |j d krtdd| _|| _t|p(|j| _|| _d S )NzEmpty path stackr   )head
ValueErrorindexr   booltailr	   r
   )selfr
   r   r	    r   @/tmp/pip-unpacked-wheel-hgp_x7fx/pyhanko_certvalidator/_state.py__init__
   s    
zValProcState.__init__c                 C   s(   ddl m} | jj}t||s"t|jS )z
        Length of the path being validated.

        .. note::
            This is the path length in the sense of RFC 5280, i.e.
            the root doesn't count.
        r   r   )pyhanko_certvalidator.pathr   r
   r   
isinstanceAssertionErrorZpkix_len)r   r   pathr   r   r   path_len   s    	zValProcState.path_len)returnc                 C   s   | j | jkS )N)r   r   )r   r   r   r   
is_ee_cert)   s    zValProcState.is_ee_cert)ee_certc                 C   s<   ddl m} | jD ]$}| }|r|j|jkr|  S qdS )a  
        Helper method to avoid recursion in indirect CRL validation.
        There are some questionable-but-technically-valid CA setups where
        a CRL issuer is authorised to assert its own revocation status,
        which could cause a naive implementation to recurse.
        r   r   N)r   r   r
   Zget_ee_cert_safesha256)r   r   r   r   certr   r   r   check_path_verif_recursion-   s    

z'ValProcState.check_path_verif_recursionc                 C   sf   | }| j dk r | jdkr d}n2| js<||M }d| j  }n| jdk	rN| j}nd}|r^d| S |S dS )zy
        :return:
            A unicode string describing the position of a certificate
            in the chain
           Ncertificatezintermediate certificate zend-entity certificatezthe )r   r   r   )r   Z
def_intermZ	never_defprefixresultr   r   r   describe_cert=   s    
zValProcState.describe_cert)FF)__name__
__module____qualname__r   r   r   strr   r   propertyr   r   r   Certificater   r#   r   r   r   r   r   	   s   
r   N)	typingr   Z
asn1cryptor   r   r   Zpyhanko_certvalidator.utilr   r   r   r   r   r   <module>   s   