
    Wwg                        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j6                  e      ZdedefdZ	 	 ddedededee   dee   defdZy)    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                   K   t        | j                  d            }t        d |D              }t        d |D              }||k\  rt	        d      t        ||d      }t        j                  |t        t              t               	      j                  |d 
      }	 t        || |j                         d {    y 7 # t        $ r}t	        d      |d }~ww xY ww)NF)include_rootc              3   4   K   | ]  }|j                     y wN)not_valid_before.0cs     Z/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko_certvalidator/ltv/ades_past.py	<genexpr>z*_past_validate_precheck.<locals>.<genexpr>(   s     8Qa((8   c              3   4   K   | ]  }|j                     y wr   )not_valid_afterr   s     r   r   z*_past_validate_precheck.<locals>.<genexpr>)   s     7Aa''7r   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es           r   _past_validate_precheckr:      s      e45E8%88K777Kk!)2
 	

 $#'!%H %,,)'4
  34 8dC 
!"99
 	
 	

  )0
 	s<   BC C :C ;C ?C C 	CCCCvalidation_data_handlersinit_control_timer$   returnc                 J  K   t        | |       d{    	 |xs$ t        j                  t        j                        }t        | ||j                  |j                  |j                  |j                         d{   }t        j                  d| j                          |       t        ||xs |d      }|j!                  ||      }t#        || |j$                  	       d{    |S 7 7 t# t        $ r"}t        d| j                                |d}~ww xY w7 8w)
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)r:   r   nowr   utcr   r'   r(   rB   rC   loggerinfodescribe_leafr   r
   r   r2   r   r3   )	r   r   r;   r<   r$   control_timer9   r7   r8   s	            r   r   r   L   sS    L "  
-N1N'/3BB4KK1@@4DD
 
 	&&()+	
 $$/?<!%H 0HH'? I  )@@   m
  ++-.0
 	6sR   D#C/D#A$C3 <C1=+C3 (A D#(D!)D#1C3 3	D<DDD#)NN) r0   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__rG   r:   r        r   <module>rZ      s      '  9 < @ 5 
 ?
			8	$+
+4+d -1.2\
\4\ 5\  )	\
 "(+\ \rY   