o
    &zh                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ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 dgZeeZdedefddZ		ddedededee dee defddZdS )    N)datetimetimezone)Optional)CertValidationPolicySpecValidationDataHandlers)ValidationError)PastValidatePrecheckFailureTimeSlideFailure)
time_slide)ValidationTimingInfo)ValidationPath)NO_REVOCATIONAcceptAllAlgorithmsCertRevTrustPolicy)async_validate_pathpast_validatepathvalidation_policy_specc              
      s   t | jdd}tdd |D }tdd |D }||kr#tdt||dd}tj|tt	d	t
 d
j|d d}zt|| |jI d H  W d S  tyY } ztd|d }~ww )NF)include_rootc                 s       | ]}|j V  qd S N)not_valid_before.0c r   ^/var/www/html/kangema/venv/lib/python3.10/site-packages/pyhanko_certvalidator/ltv/ades_past.py	<genexpr>(       z*_past_validate_precheck.<locals>.<genexpr>c                 s   r   r   )not_valid_afterr   r   r   r   r   )   r   z`The intersection of the validity periods of the certificates in the path is empty or degenerate.Tvalidation_timebest_signature_timepoint_in_time_validation)revocation_checking_policy)revinfo_policyalgorithm_usage_policytiming_infohandlersz\Elementary path validation routine failed during pre-check for past point-in-time validation)list
iter_certsmaxminr   r   dataclassesreplacer   r   r   build_validation_contextr   pkix_validation_paramsr   )r   r   certslower_boundupper_boundref_timevalidation_contexter   r   r   _past_validate_precheck   sH   	r8   validation_data_handlersinit_control_timer"   returnc           	   
      s   t | |I dH  z'|ptjtjd}t| ||j|j|j|j	dI dH }t
d|   | W n tyF } z
td|   |d}~ww t||pL|dd}|j||d}t|| |jd	I dH  |S )
u  
    Execute the ETSI EN 319 102-1 past certificate validation algorithm
    against the given path (ETSI EN 319 102-1, § 5.6.2.1).

    Instead of merely evaluating X.509 validation constraints, the algorithm
    will perform a full point-in-time reevaluation of the path at the
    control time mandated by the specification. This implies that a caller
    implementing the past signature validation algorithm no longer needs to
    explicitly reevaluate CA certificate revocation times and/or algorithm
    constraints based on POEs.

    .. warning::
        This is incubating internal API.

    :param path:
        The prospective validation path against which to execute the algorithm.
    :param validation_policy_spec:
        The validation policy specification.
    :param validation_data_handlers:
        The handlers used to manage collected certificates,revocation
        information and proof-of-existence records.
    :param init_control_time:
        Initial control time; defaults to the current time.
    :param best_signature_time:
        Usage time to use in freshness computations.
    :return:
        The control time returned by the time sliding algorithm.
        Informally, the last time at which the certificate was known to be
        valid.
    N)tz)r:   rev_trust_policyalgo_usage_policytime_tolerancerevinfo_managerzAAdES time slide yields %s as the control time for path with leaf zKFailed to get control time for point-in-time validation for path with leaf Tr    r'   )
parameters)r8   r   nowr   utcr
   r%   r&   r?   r@   loggerinfodescribe_leafr   r	   r   r0   r   r1   )	r   r   r9   r:   r"   control_timer7   r5   r6   r   r   r   r   L   sZ   &
)NN) r.   loggingr   r   typingr   pyhanko_certvalidator.contextr   r   pyhanko_certvalidator.errorsr    pyhanko_certvalidator.ltv.errorsr   r	   $pyhanko_certvalidator.ltv.time_slider
   pyhanko_certvalidator.ltv.typesr   pyhanko_certvalidator.pathr   !pyhanko_certvalidator.policy_declr   r   r   pyhanko_certvalidator.validater   __all__	getLogger__name__rD   r8   r   r   r   r   r   <module>   sD    

2