o
    vh                     @   s   d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	m
Z
mZmZ ddlmZ ddlmZ g dZd	e ZG d
d dejZG dd dejZG dd dejZeddG dd dZG dd dejZdS )zF
Asynchronous API for fetching OCSP responses, CRLs and certificates.
    N)	dataclass)AsyncGeneratorIterableUnion)cmscrlocspx509)	Authority)__version__)OCSPFetcher
CRLFetcherCertificateFetcherFetchersFetcherBackendDEFAULT_USER_AGENTzpyhanko_certvalidator %sc                   @   sl   e Zd ZdZdeejejf de	de
jfddZdee
j fddZdeejejf dee
j fd	d
ZdS )r   z4Utility interface to fetch and cache OCSP responses.cert	authorityreturnc                       t )ag  
        Fetch an OCSP response for a certificate.

        :param cert:
            The certificate for which an OCSP response has to be fetched.
        :param authority:
            The issuing authority.
        :raises:
            OCSPFetchError - Raised if an OCSP response could not be obtained.
        :return:
            An OCSP response.
        NotImplementedError)selfr   r    r   `/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/pyhanko_certvalidator/fetchers/api.pyfetch   s   zOCSPFetcher.fetchc                 C      t )zD
        Return all responses fetched by this OCSP fetcher.
        r   r   r   r   r   fetched_responses/      zOCSPFetcher.fetched_responsesc                 C   r   )z
        Return all responses fetched by this OCSP fetcher that are relevant
        to determine the revocation status of the given certificate.
        r   r   r   r   r   r   fetched_responses_for_cert5      z&OCSPFetcher.fetched_responses_for_certN)__name__
__module____qualname____doc__r   r	   Certificater   AttributeCertificateV2r
   r   OCSPResponser   r   r   r!   r   r   r   r   r      s    
r   c                   @   sr   e Zd ZdZdddeejejf de	e
j fddZde	e
j fdd	Zdeejejf de	e
j fd
dZdS )r   z*Utility interface to fetch and cache CRLs.N)
use_deltasr   r   c                   r   )a  
        Fetches the CRLs for a certificate.

        :param cert:
            An asn1crypto.x509.Certificate object to get the CRL for

        :param use_deltas:
            A boolean indicating if delta CRLs should be fetched

        :raises:
            CRLFetchError - when a network/IO error or decoding error occurs

        :return:
            An iterable of CRLs fetched.
        r   )r   r   r*   r   r   r   r   B   s   zCRLFetcher.fetchc                 C   r   )z>
        Return all CRLs fetched by this CRL fetcher.
        r   r   r   r   r   fetched_crls^   r   zCRLFetcher.fetched_crlsc                 C   r   )a  
        Return all relevant fetched CRLs for the given certificate

        :param cert:
            A certificate.
        :return:
            An iterable of CRLs
        :raise KeyError:
            if no fetch operations have been performed for this certificate
        r   r    r   r   r   fetched_crls_for_certd   s   z CRLFetcher.fetched_crls_for_cert)r#   r$   r%   r&   r   r	   r'   r   r(   r   r   CertificateListr   r+   r,   r   r   r   r   r   ?   s    
r   c                   @   sd   e Zd ZdZdeejejf de	ejdf fddZ
de	ejdf fddZdeej fd	d
ZdS )r   z2Utility interface to fetch and cache certificates.r   r   Nc                 C   r   )a  
        Fetches certificates from the authority information access extension of
        a certificate.

        :param cert:
            A certificate

        :raises:
            CertificateFetchError - when a network I/O or decoding error occurs

        :return:
            An asynchronous generator yielding asn1crypto.x509.Certificate
            objects that were fetched.
        r   r    r   r   r   fetch_cert_issuersw      z%CertificateFetcher.fetch_cert_issuersc                 C   r   )a  
        Fetches certificates from the authority information access extension of
        an asn1crypto.crl.CertificateList.

        :param certificate_list:
            An asn1crypto.crl.CertificateList object

        :raises:
            CertificateFetchError - when a network I/O or decoding error occurs

        :return:
            An asynchronous generator yielding asn1crypto.x509.Certificate
            objects that were fetched.
        r   )r   certificate_listr   r   r   fetch_crl_issuers   r/   z$CertificateFetcher.fetch_crl_issuersc                 C   r   )zP
        Return all certificates retrieved by this certificate fetcher.
        r   r   r   r   r   fetched_certs   r   z CertificateFetcher.fetched_certs)r#   r$   r%   r&   r   r	   r'   r   r(   r   r.   r1   r   r2   r   r   r   r   r   t   s    

r   T)frozenc                   @   s*   e Zd ZU dZeed< eed< eed< dS )r   z
    Models a collection of fetchers to be used by a validation context.

    The intention is that these can share resources (like a connection pool)
    in a unified, controlled manner. See also :class:`.FetcherBackend`.
    ocsp_fetchercrl_fetchercert_fetcherN)r#   r$   r%   r&   r   __annotations__r   r   r   r   r   r   r      s
   
 r   c                   @   s<   e Zd ZdZdefddZdd ZdefddZd	d
 ZdS )r   a  
    Generic, bare-bones interface to help abstract away instantiation logic for
    fetcher implementations.

    Intended to operate as an asynchronous context manager, with
    `async with backend_obj as fetchers: ...` putting the resulting
    :class:`.Fetchers` object in to the variable named `fetchers`.

    .. note::
        The initialisation part of the API is necessarily synchronous,
        for backwards compatibility with the old ``ValidationContext`` API.
        If you need asynchronous resource management, handle it elsewhere,
        or use some form of lazy resource provisioning.

        Alternatively, you can pass :class:`Fetchers` objects to the validation
        context yourself, and forgo use of the :class:`.FetcherBackend`
        API altogether.
    r   c                 C   r   )zl
        Set up fetchers synchronously.

        .. note::
            This is a synchronous method
        r   r   r   r   r   get_fetchers   r"   zFetcherBackend.get_fetchersc                    s   dS )zf
        Clean up the resources associated with this fetcher backend,
        asynchronously.
        Nr   r   r   r   r   close   s   zFetcherBackend.closec                    s
   |   S N)r8   r   r   r   r   
__aenter__   s   zFetcherBackend.__aenter__c                    s   |   I d H S r:   )r9   )r   exc_typeexc_valexc_tbr   r   r   	__aexit__   s   zFetcherBackend.__aexit__N)	r#   r$   r%   r&   r   r8   r9   r;   r?   r   r   r   r   r      s    	r   )r&   abcdataclassesr   typingr   r   r   
asn1cryptor   r   r   r	   pyhanko_certvalidator.authorityr
   pyhanko_certvalidator.versionr   __all__r   ABCr   r   r   r   r   r   r   r   r   <module>   s    	&50