
    Wwg                        d dl Z d dlZd dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
mZ d dlmZmZ d dlmZmZ g dZe j&                   G d d	e j(                               Zeeeeej.                  f   Zd
ede
e   fdZ ed       G d d             Ze j&                   G d de j(                               Z ed       G d d             ZdedefdZ G d d      Zy)    N)	dataclass)datetimetimezone)AnyDictIteratorOptionalUnion)corex509)CRLContainerOCSPContainer)ValidationObjectTypeValidationObjectPOETypeKnownPOE
POEManagerdigest_for_poec                   6    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
 Zy)r   zF
    Types of validation objects recognised by ETSI TS 119 102-2.
    certificateCRLOCSPResponse	timestampevidencerecord	publicKey
signedDataotherc                      d| j                    S )Nz!urn:etsi:019102:validationObject:valueselfs    T/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko_certvalidator/ltv/poe.pyurnzValidationObjectType.urn$   s    24::,??    N)__name__
__module____qualname____doc__CERTIFICATEr   OCSP_RESPONSE	TIMESTAMPEVIDENCE_RECORD
PUBLIC_KEYSIGNED_DATAOTHERr$    r%   r#   r   r      s7      K
C"MI&OJKE@r%   r   thingreturnc                     t        | t              rt        j                  S t        | t              rt        j
                  S t        | t        j                        rt        j                  S y N)	
isinstancer   r   r   r   r+   r   Certificater*   )r2   s    r#   guess_validation_object_typer8   +   sO     %&#'''	E=	)#111	E4++	,#///r%   T)frozenc                   (    e Zd ZU dZeed<   	 eed<   y)r   z
    A validation object used in the course of a validation operation
    for which proofs of existence can potentially be gathered.
    object_typer    N)r&   r'   r(   r)   r   __annotations__r   r1   r%   r#   r   r   7   s     
 &% J	r%   r   c                   .    e Zd ZdZdZdZedefd       Zy)r   provided
validationpolicyr3   c                      d| j                    S )Nzurn:etsi:019102:poetype:r   r!   s    r#   r$   zPOEType.urnV   s    )$**66r%   N)	r&   r'   r(   PROVIDED
VALIDATIONPOLICYpropertystrr$   r1   r%   r#   r   r   P   s*    HJF7S 7 7r%   r   c                   @    e Zd ZU eed<   eed<   eed<   dZee	   ed<   y)r   poe_typedigestpoe_timeNvalidation_object)
r&   r'   r(   r   r<   bytesr   rK   r	   r   r1   r%   r#   r   r   [   s$    M48x 018r%   r   datac                 H    t        j                  |       j                         S r5   )hashlibsha256rI   )rM   s    r#   r   r   c   s    >>$&&((r%   c            	           e Zd ZdZddee   fdZ	 ddededee   de	fd	Z
	 dd
ededee   de	fdZde	de	fdZdee	   fdZdedefdZd Zd Zy)r   z~
    Class to manage proof-of-existence (POE) claims.

    :param current_dt_override:
        Override the current time.
    Ncurrent_dt_overridec                      i | _         || _        y r5   )_poes_current_dt_override)r"   rR   s     r#   __init__zPOEManager.__init__o   s    ,.
$7!r%   rM   rH   dtr3   c                 *   t        |t              r|}nt        |t        j                        r|j	                         }n\t        |t
              r|j                  j	                         }n1t        |t              r|j                  j	                         }nt        t        |      }|xs1 | j                  xs# t        j                  t        j                        }t!        |      }d}|rt#        ||      }| j%                  t'        ||||            S )ao  
        Register a new POE claim if no POE for an earlier time is available.

        :param data:
            Data to register a POE claim for.
        :param poe_type:
            The type of POE.
        :param dt:
            The POE time to register. If ``None``, assume the current time.
        :return:
            The oldest POE datetime available.
        N)r;   r    rH   rI   rJ   rK   )r6   rL   r   	Asn1Valuedumpr   crl_datar   ocsp_response_dataNotImplementedErrorr   rU   r   nowr   utcr8   r   register_known_poer   )r"   rM   rH   rW   b_datarI   vo_typevos           r#   registerzPOEManager.registers   s    $ dE"Fdnn-YY[Fl+]]'')Fm,,,113F%%'J4,,JX\\0J.t4!gTBB&&!"$	
 	
r%   rI   c                     |xs1 | j                   xs# t        j                  t        j                        }| j                  t        |||d            S )a  
        Register a new POE claim if no POE for an earlier time is available.

        :param digest:
            SHA-256 digest of the data to register a POE claim for.
        :param dt:
            The POE time to register. If ``None``, assume the current time.
        :param poe_type:
            The type of POE.
        :return:
            The oldest POE datetime available.
        NrY   )rU   r   r_   r   r`   ra   r   )r"   rI   rH   rW   s       r#   register_by_digestzPOEManager.register_by_digest   sM    $ J4,,JX\\0J&&!"&	
 	
r%   	known_poec                     |j                   }|j                  }	 | j                  |   }|j                   |k  r|S 	 || j                  |<   |S # t        $ r Y w xY w)z
        Register a new POE claim if no POE for an earlier time is available.

        :param known_poe:
            The POE object to register.
        :return:
            The oldest POE for the given digest.
        )rJ   rI   rT   KeyError)r"   rh   rW   rI   cur_poes        r#   ra   zPOEManager.register_known_poe   so     !!	jj(G2% & '

6  		s   A 	AAc                 H    t        | j                  j                               S )z
        Iterate over the current earliest known POE for all items currently
        being managed.

        Returns an iterator with :class:`KnownPOE` objects.
        )iterrT   valuesr!   s    r#   __iter__zPOEManager.__iter__   s     DJJ%%'((r%   itemc                 Z    | j                  |t        j                  d      j                  S )a  
        Return the earliest available POE for an item.

        .. note::
            This is a wrapper around :meth:`register` with `dt=None`, and hence
            will register the current time as the POE time for the given item.
            This side effect is intentional.

        :param item:
            Item to get the current POE time for.
        :return:
            A datetime object representing the earliest available POE for the
            item.
        N)rH   rW   )re   r   rC   rJ   )r"   rp   s     r#   __getitem__zPOEManager.__getitem__   s,     }}7--$  

(	r%   c                 r    t        |t              st        t        |      D ]  }| j	                  |        y)ze
        Combine data in another POE manager with the POEs managed by this
        instance.
        N)r6   r   	TypeErrorrm   ra   )r"   r   poes      r#   __ior__zPOEManager.__ior__   s4    
 %,O; 	)C##C(	)r%   c                 f    t        | j                        }t        | j                        |_        |S )N)rR   )r   rU   dictrT   )r"   new_instances     r#   __copy__zPOEManager.__copy__   s)    !d6O6OP!$**-r%   r5   )r&   r'   r(   r)   r	   r   rV   KnownObjectTyper   r   re   rL   rg   ra   r   ro   rr   rv   rz   r1   r%   r#   r   r   g   s    8HX,> 8 "&	*
*
 *
 X	*

 
*
` "&	

 
 X	

 

8H  ()(8, ) H &)r%   r   ) enumrO   dataclassesr   r   r   typingr   r   r   r	   r
   
asn1cryptor   r   &pyhanko_certvalidator.revinfo.archivalr   r   __all__uniqueEnumr   rL   r7   r{   objectr8   r   r   r   r   r   r1   r%   r#   <module>r      s      ! ' 7 7 ! N @499 @ @$ |]D<L<LLM		"#	 $  0 7dii 7 7 $9 9 9) )5 )Q Qr%   