
    h+                     B    d Z ddlmZ ddlmZ ddlmZ  G d de      Zy)z%Utilities for caching OCSP responses.    )
namedtuple)datetime)Lockc                   >    e Zd ZdZ edg d      Zd Zd Zd Z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    P/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pymongo/ocsp_cache.py__init__z_OCSPCache.__init__   s    
V
    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                  |      }|j                  &| j                  j	                  |d       	 ddd       y|j
                  t        j                         cxk  r|j                  k  sn 	 ddd       y| j                  j                  |d      }||j                  |j                  k  r|| j                  |<   ddd       y# 1 sw Y   yxY w)zAdd/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)	r   r   next_updater   popthis_update	_datetimeutcnowget)r   keyvalue	cache_keycached_values        r   __setitem__z_OCSPCache.__setitem__+   s     ZZ 	.++C0I
   (

y$/	. 	. %%)9)9);Oe>O>OO	. 	.   ::>>)T:L#|'?'?%BSBS'S(-

9%%	. 	. 	.s   ;C4CACC&c                 @   | j                   5  | j                  |      }| j                  |   }|j                  t	        j
                         cxk  r|j                  k  rn n|cddd       S | j                  j                  |d       t        |      # 1 sw Y   yxY w)zGet a cache entry if it exists.

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

        Raises KeyError if the item is not in the cache.
        N)	r   r   r   r   r   r    r   r   KeyError)r   itemr$   r#   s       r   __getitem__z_OCSPCache.__getitem__G   s     ZZ 		&++D1IJJy)E   I$4$4$6J9J9JJ		& 		& JJNN9d+9%%		& 		&s   AB-'BBN)
__name__
__module____qualname____doc__r   r   r   r   r&   r*    r   r   r   r      s)    %RN


.8&r   r   N)	r.   collectionsr   r   r   	threadingr   objectr   r/   r   r   <module>r3      s!    , " * A& A&r   