
    Wwg                     F   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  Z G d
 dej&                        Z G d dej&                        Z G d dej&                        Z ed       G d d             Z G d dej&                        Zy)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                       e Zd ZdZdeej                  ej                  f   de	de
j                  fdZdee
j                     fdZdeej                  ej                  f   dee
j                     fdZy)	r   z4Utility interface to fetch and cache OCSP responses.cert	authorityreturnc                    K   t         w)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   s      Y/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko_certvalidator/fetchers/api.pyfetchzOCSPFetcher.fetch   s     " "!   	c                     t         )zD
        Return all responses fetched by this OCSP fetcher.
        r   r   s    r   fetched_responseszOCSPFetcher.fetched_responses0   
     "!    c                     t         )z
        Return all responses fetched by this OCSP fetcher that are relevant
        to determine the revocation status of the given certificate.
        r   r   r   s     r   fetched_responses_for_certz&OCSPFetcher.fetched_responses_for_cert6   
     "!r"   N)__name__
__module____qualname____doc__r   r
   Certificater   AttributeCertificateV2r   r	   OCSPResponser   r   r    r%    r"   r   r   r      s    >"D$$c&@&@@A" " 
			"&"8D,=,=#> ""$**C,F,FFG"	$##	$"r"   r   c                       e Zd ZdZdddeej                  ej                  f   de	e
j                     fdZde	e
j                     fdZdeej                  ej                  f   de	e
j                     fdZy)	r   z*Utility interface to fetch and cache CRLs.N)
use_deltasr   r   c                   K   t         w)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   r0   s      r   r   zCRLFetcher.fetchC   s     4 "!r   c                     t         )z>
        Return all CRLs fetched by this CRL fetcher.
        r   r   s    r   fetched_crlszCRLFetcher.fetched_crls_   r!   r"   c                     t         )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$   s     r   fetched_crls_for_certz CRLFetcher.fetched_crls_for_certe   s
     "!r"   )r'   r(   r)   r*   r   r
   r+   r   r,   r   r   CertificateListr   r3   r5   r.   r"   r   r   r   @   s    4 	"D$$c&@&@@A"
 
#%%	&"8"hs':':; ""$**C,F,FFG"	#%%	&"r"   r   c                       e Zd ZdZdeej                  ej                  f   de	ej                  df   fdZ
de	ej                  df   fdZdeej                     fdZy)r   z2Utility interface to fetch and cache certificates.r   r   Nc                     t         )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$   s     r   fetch_cert_issuersz%CertificateFetcher.fetch_cert_issuersx   
    " "!r"   c                     t         )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_lists     r   fetch_crl_issuersz$CertificateFetcher.fetch_crl_issuers   r:   r"   c                     t         )zP
        Return all certificates retrieved by this certificate fetcher.
        r   r   s    r   fetched_certsz CertificateFetcher.fetched_certs   r!   r"   )r'   r(   r)   r*   r   r
   r+   r   r,   r   r9   r=   r   r?   r.   r"   r   r   r   u   st    <"$**C,F,FFG"	(($.	/"&"	(($.	/"&"x(8(89 "r"   r   T)frozenc                   0    e Zd ZU dZeed<   eed<   eed<   y)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"   r   c                   4    e Zd ZdZdefdZd ZdefdZd Zy)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                     t         )zl
        Set up fetchers synchronously.

        .. note::
            This is a synchronous method
        r   r   s    r   get_fetcherszFetcherBackend.get_fetchers   r&   r"   c                    K   yw)zf
        Clean up the resources associated with this fetcher backend,
        asynchronously.
        Nr.   r   s    r   closezFetcherBackend.close   s     
 	s   c                 *   K   | j                         S wN)rH   r   s    r   
__aenter__zFetcherBackend.__aenter__   s       ""s   c                 >   K   | j                          d {   S 7 wrL   )rJ   )r   exc_typeexc_valexc_tbs       r   	__aexit__zFetcherBackend.__aexit__   s     ZZ\!!!s   N)	r'   r(   r)   r*   r   rH   rJ   rM   rR   r.   r"   r   r   r      s)    &"h "#( #"r"   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   <module>r[      s     ! 2 2 + + 5 5 0+= #"#'' #"L2" 2"j-" -"` $
% 
% 
%("SWW ("r"   