Ë
    Ü_Ëiâ  ã                  ó�   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ e	rddlmZmZ dd	„Zdd
„Z G d„ d«      Zy)z%Utilities for caching OCSP responses.é    )Úannotations)Ú
namedtuple)Údatetime)Útimezone)ÚTYPE_CHECKINGÚAnyÚOptional)Ú_create_lock)ÚOCSPRequestÚOCSPResponsec                óJ   — t        | d«      r| j                  S | j                  S )z7Compat helper to return the response's next_update_utc.Únext_update_utc)Úhasattrr   Únext_update©Úvalues    úU/var/www/pod-logistic/pod-api/venv/lib/python3.12/site-packages/pymongo/ocsp_cache.pyÚ_next_updater      ó'   € ô ˆuÐ'Ô(Ø×$Ñ$Ð$Ø×ÑÐó    c                óJ   — t        | d«      r| j                  S | j                  S )z7Compat helper to return the response's this_update_utc.Úthis_update_utc)r   r   Úthis_updater   s    r   Ú_this_updater   &   r   r   c                  óF   — e Zd ZdZ edg d¢«      Zd	d„Zd
d„Zdd„Zdd„Z	y)Ú
_OCSPCachezA cache for OCSP responses.ÚOcspResponseCacheKey©Úhash_algorithmÚissuer_name_hashÚissuer_key_hashÚserial_numberc                ó0   — i | _         t        «       | _        y )N)Ú_datar
   Ú_lock)Úselfs    r   Ú__init__z_OCSPCache.__init__6   s   € Ø.0ˆŒ
ä!“^ˆ�
r   c                ó¬   — | j                  |j                  j                  j                  «       |j                  |j
                  |j                  ¬«      S )Nr   )ÚCACHE_KEY_TYPEr   ÚnameÚlowerr    r!   r"   )r&   Úocsp_requests     r   Ú_get_cache_keyz_OCSPCache._get_cache_key;   sM   € Ø×"Ñ"Ø'×6Ñ6×;Ñ;×AÑAÓCØ)×:Ñ:Ø(×8Ñ8Ø&×4Ñ4ð	 #ó 
ð 	
r   c                ó^  — | j                   5  | j                  |«      }t        |«      }|€&| j                  j	                  |d«       	 ddd«       yt        |«      }|€
	 ddd«       yt        j                  t        j                  ¬«      }|j                  €|j                  d¬«      }||cxk  r|k  sn 	 ddd«       y| j                  j                  |d«      }|€|| j                  |<   	 ddd«       yt        |«      }|�||k  r|| j                  |<   ddd«       y# 1 sw Y   yxY w)zàAdd/update a cache entry.

        'key' is of type cryptography.x509.ocsp.OCSPRequest
        'value' is of type cryptography.x509.ocsp.OCSPResponse

        Validity of the OCSP response must be checked by caller.
        N©Útz©Útzinfo)r%   r-   r   r$   Úpopr   Ú	_datetimeÚnowr   Úutcr2   ÚreplaceÚget)	r&   Úkeyr   Ú	cache_keyr   r   r5   Úcached_valueÚcached_next_updates	            r   Ú__setitem__z_OCSPCache.__setitem__C   s*  € ð �Z‰Zñ 	.Ø×+Ñ+¨CÓ0ˆIô
 ' uÓ-ˆKØÐ"Ø—
‘
—‘˜y¨$Ô/Ø÷	.ð 	.ô ' uÓ-ˆKØÐ"Ø÷	.ð 	.ô —-‘-¤8§<¡<Ô0ˆCØ×!Ñ!Ð)à—k‘k¨�kÓ.�à 3Ô4¨Ô4Ø÷)	.ð 	.ð0  Ÿ:™:Ÿ>™>¨)°TÓ:ˆLØÐ#Ø(-�—
‘
˜9Ñ%Ø÷7	.ð 	.ô8 ".¨lÓ!;ÐØ!Ð-Ð2DÀ{Ò2RØ(-�—
‘
˜9Ñ%÷=	.÷ 	.ñ 	.ús$   �<D#ÁD#Á)AD#Ã.D#Ã9!D#Ä#D,c                ó´  — | j                   5  | j                  |«      }| j                  |   }t        |«      }t	        |«      }|€J ‚|€J ‚t        j                  t        j                  ¬«      }|j                  €|j                  d¬«      }||cxk  r|k  rn n|cddd«       S | j                  j                  |d«       t        |«      ‚# 1 sw Y   yxY w)z Get a cache entry if it exists.

        'item' is of type cryptography.x509.ocsp.OCSPRequest

        Raises KeyError if the item is not in the cache.
        Nr/   r1   )r%   r-   r$   r   r   r4   r5   r   r6   r2   r7   r3   ÚKeyError)r&   Úitemr:   r   r   r   r5   s          r   Ú__getitem__z_OCSPCache.__getitem__k   sÎ   € ð �Z‰Zñ 	&Ø×+Ñ+¨DÓ1ˆIØ—J‘J˜yÑ)ˆEô ' uÓ-ˆKÜ& uÓ-ˆKØÐ*Ð*Ð*ØÐ*Ð*Ð*Ü—-‘-¤8§<¡<Ô0ˆCØ×!Ñ!Ð)à—k‘k¨�kÓ.�Ø˜cÔ/ KÕ/Ø÷	&ñ 	&ð  �J‰J�N‰N˜9 dÔ+Ü˜9Ó%Ð%÷#	&ð 	&ús   �BCÂ''CÃCN)ÚreturnÚNone)r,   r   rB   r)   )r9   r   r   r   rB   rC   )r@   r   rB   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r)   r'   r-   r=   rA   © r   r   r   r   .   s*   „ Ù%áØÚRó€Nó
$ó

ó&.ôP&r   r   N)r   r   rB   zOptional[_datetime])rG   Ú
__future__r   Úcollectionsr   r   r4   r   Útypingr   r   r	   Úpymongo.lockr
   Úcryptography.x509.ocspr   r   r   r   r   rH   r   r   ú<module>rN      s;   ðñ ,å "å "Ý *Ý ß /Ñ /å %áß@óó÷U&ò U&r   