
    Wwgm7              
       v   d dl Z d dlZd dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZmZmZ d dlmZ d dlmZmZ d dlmZmZmZ g d	Z G d
 dej2                        Z ed       G d d             Z G d dee j8                        Z e	de      Zdee   dee   fdZd Z dee   dee   dededef
dZ!deejD                     fdZ# ed       G d de             Z$ ed       G d  d!e             Z%e
e&ejN                  e%f   Z(e
e&ejR                  e$f   Z*d"ee(   dee%   fd#Z+d$ee*   dee$   fd%Z,y)&    N)	dataclass)datetime)IterableListOptionalTypeVarUnion)algoscrlocsp)	type_name)IssuedItemContainerValidationTimingParams)#FRESHNESS_FALLBACK_VALIDITY_DEFAULTCertRevTrustPolicyFreshnessReqType)RevinfoUsabilityRatingRevinfoUsabilityRevinfoContainerOCSPContainerCRLContainersort_freshest_firstprocess_legacy_crl_inputprocess_legacy_ocsp_inputc                       e Zd ZdZ ej
                         Z	  ej
                         Z	  ej
                         Z	  ej
                         Z		 e
defd       Zy)r   zz
    Description of whether a piece of revocation information
    is considered usable in the circumstances provided.
    returnc                 F    | t         j                  t         j                  fv S )zs
        Boolean indicating whether the assigned rating corresponds to
        a "fresh" judgment in AdES.
        )r   OKTOO_NEWselfs    ]/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko_certvalidator/revinfo/archival.pyusable_adesz"RevinfoUsabilityRating.usable_ades>   s(     "%%"**
 
 	
    N)__name__
__module____qualname____doc__enumautor   STALEr   UNCLEARpropertyboolr#    r$   r"   r   r       sr    
 
B DIIKE diikG diikG
 	
T 	
 	
r$   r   T)frozenc                   2    e Zd ZU dZeed<   	 dZee   ed<   y)r   z`
    Usability rating and cutoff date for a particular piece of
    revocation information.
    ratingNlast_usable_at)	r%   r&   r'   r(   r   __annotations__r3   r   r   r/   r$   r"   r   r   K   s*    
 #" *.NHX&-r$   r   c                   T    e Zd ZdZdededefdZede	e
j                     fd       Zy)r   z<
    A container for a piece of revocation information.
    policytiming_paramsr   c                     t         )af  
        Assess the usability of the revocation information given a
        revocation information trust policy and timing parameters.

        :param policy:
            The revocation information trust policy.
        :param timing_params:
            Timing-related information.
        :return:
            A :class:`.RevinfoUsability` judgment.
        NotImplementedError)r!   r6   r7   s      r"   	usable_atzRevinfoContainer.usable_atc   s
     "!r$   c                     t         )z
        Extract the signature mechanism used to guarantee the authenticity
        of the revocation information, if applicable.
        r9   r    s    r"   revinfo_sig_mechanism_usedz+RevinfoContainer.revinfo_sig_mechanism_useds   s
     "!r$   N)r%   r&   r'   r(   r   r   r   r;   r-   r   r
   SignedDigestAlgorithmr=   r/   r$   r"   r   r   ^   sK    "("9O"	"  "	%--	." "r$   r   RevInfoType)boundlstr   c                 2    dt         fd}t        | |d      S )aV  
    Sort a list of revocation information containers in freshest-first order.

    Revocation information that does not have a well-defined issuance date
    will be grouped at the end.

    :param lst:
        A list of :class:`.RevinfoContainer` objects of the same type.
    :return:
        The same list sorted from fresh to stale.
    	containerc                 &    | j                   }|d u|fS N)issuance_date)rC   dts     r"   _keyz!sort_freshest_first.<locals>._key   s    $$ ~r!!r$   T)keyreverse)r   sorted)rA   rH   s     r"   r   r      s     "( " #4..r$   c                 Z    | j                   }||
||k\  r||z
  }|t        |      |z   }|S rE   )	freshnessabs)r6   this_updatenext_updatetime_tolerancefreshness_deltas        r"   _freshness_deltarS      sE    &&O"{k'A)K7O"o.?r$   rO   rP   r6   r7   c                 j   | t        t        j                        S |j                  }|j                  }|j
                  t        j                  k(  r\t        || ||      }|t        t        j                        S |j                  }| |z
  |k  rt        t        j                  | |z         S |j
                  t        j                  k(  rOt        || ||      }|t        t        j                        S | ||z
  k  rt        t        j                  | |z         S |j
                  t        j                  k(  r`|	| t        z   }|j                  }|s!|| |z
  k  rt        t        j                        S |||z   kD  r$t        t        j                  ||z         S t         t        t        j"                        S )N)r3   )r   r   r,   validation_timerQ   freshness_req_typer   TIME_AFTER_SIGNATURErS   best_signature_timer+   MAX_DIFF_REVOCATION_VALIDATIONDEFAULTr   retroactive_revinfor   r:   r   )	rO   rP   r6   r7   rU   rQ   rR   signature_poe_timeretroactives	            r"   _judge_revinfor^      s     6 > >??#33O"11N   $4$I$II +Kn
 "#$:$B$BCC*>>++o=#&,,*_< 
 	!!::	; +Kn
 "#$:$B$BCC
 ?::#&,,*_<  
	"	"&6&>&>	>  &(KKK00~1MM#$:$B$BCC[>99#&,,*^; 
 "!25566r$   c                 z    | d   j                   }|dk7  ry | d   }|d   j                   dk7  ry |d   j                  S )Nresponse_status
successfulresponse_bytesresponse_typebasic_ocsp_responseresponse)nativeparsed)ocsp_responsestatusrb   s      r"   _extract_basic_ocsp_responserj      sS     ,-44F"#34No&--1FF*%,,,r$   c                   "   e Zd ZU dZej
                  ed<   	 dZeed<   	 e	dej
                  de
d    fd       Zedee   fd       Zd	ed
edefdZdeej(                     fdZdeej,                     fdZedeej2                     fd       Zy)r   z)
    Container for an OCSP response.
    ocsp_response_datar   indexrh   r   c                     t        |      }|g S |d   }t        t        |d               D cg c]  }t        ||       c}S c c}w )a  
        Turn an OCSP response object into one or more :class:`.OCSPContainer`
        objects. If a :class:`.OCSPContainer` contains more than one
        ``SingleResponse``, then the same OCSP response will be duplicated
        into multiple containers, each with a different ``index`` value.

        :param ocsp_response:
            An OCSP response.
        :return:
            A list of :class:`.OCSPContainer` objects, one for each
            ``SingleResponse`` value.
        tbs_response_data	responses)rl   rm   )rj   rangelenr   )clsrh   rd   tbs_responseixs        r"   
load_multizOCSPContainer.load_multi  s]    " ;=I&I*+>? C[ 9:;
 ]"E
 	
 
s   Ac                 F    | j                         }|y |d   j                  S )NrO   )extract_single_responserf   )r!   cert_responses     r"   rF   zOCSPContainer.issuance_date/  s*    446 ]+222r$   r6   r7   c                     | j                         }|t        t        j                        S |d   j                  }|d   j                  }t        ||||      S )NrO   rP   r6   r7   )rx   r   r   r,   rf   r^   )r!   r6   r7   ry   rO   rP   s         r"   r;   zOCSPContainer.usable_at7  sc     446 #$:$B$BCC#M299#M299'	
 	
r$   c                 ,    t        | j                        S )z
        Extract the ``BasicOCSPResponse``, assuming there is one (i.e.
        the OCSP response is a standard, non-error response).
        )rj   rl   r    s    r"   extract_basic_ocsp_responsez)OCSPContainer.extract_basic_ocsp_responseG  s     ,D,C,CDDr$   c                     | j                         }|y|d   }t        |d         | j                  k  ry|d   | j                     S )z^
        Extract the unique ``SingleResponse`` value identified by the
        index.
        Nro   rp   )r}   rr   rm   )r!   rd   rt   s      r"   rx   z%OCSPContainer.extract_single_responseO  sT     #>>@&*+>?|K()TZZ7K(44r$   c                 4    | j                         }|d S |d   S Nsignature_algorithm)r}   )r!   
basic_resps     r"   r=   z(OCSPContainer.revinfo_sig_mechanism_used^  s(     557
!)tPz:O/PPr$   N)r%   r&   r'   r(   r   OCSPResponser4   rm   intclassmethodr   rv   r-   r   r   rF   r   r   r   r;   BasicOCSPResponser}   SingleResponserx   r
   r>   r=   r/   r$   r"   r   r     s     ))) E3N
 
 --
	o	
 
4 3x1 3 3
(
9O
	
 EXd6L6L-M E5$2E2E)F 5 Q	%--	.Q Qr$   r   c                       e Zd ZU dZej
                  ed<   	 dedede	fdZ
edee   fd       Zedej                   fd       Zy	)
r   z<
    Container for a certificate revocation list (CRL).
    crl_datar6   r7   r   c                 z    | j                   d   }|d   j                  }|d   j                  }t        ||||      S )Ntbs_cert_listrO   rP   r{   )r   rf   r^   )r!   r6   r7   r   rO   rP   s         r"   r;   zCRLContainer.usable_atq  sH     o6#M299#M299V=
 	
r$   c                 >    | j                   d   }|d   j                  S )Nr   rO   )r   rf   )r!   r   s     r"   rF   zCRLContainer.issuance_date{  s!    o6]+222r$   c                      | j                   d   S r   )r   r    s    r"   r=   z'CRLContainer.revinfo_sig_mechanism_used  s    }}233r$   N)r%   r&   r'   r(   r   CertificateListr4   r   r   r   r;   r-   r   r   rF   r
   r>   r=   r/   r$   r"   r   r   f  sx     !!!
(
9O
	
 3x1 3 3 4E,G,G 4 4r$   r   crlsc                 0   g }| D ]  }t        |t              rt        j                  j	                  |      }t        |t        j                        rt        |      }t        |t
              r|j                  |       yt        dt        |              |S )z
    Internal function to process legacy CRL data into one or more
    :class:`.CRLContainer`.

    :param crls:
        Legacy CRL input data.
    :return:
        A list of :class:`.CRLContainer` objects.
    zScrls must be a list of byte strings or asn1crypto.crl.CertificateList objects, not )	
isinstancebytesr   r   loadr   append	TypeErrorr   )r   new_crlscrl_s      r"   r   r     s     H dE"&&++D1DdC//0%DdL)OOD!??H>OQ  Or$   ocspsc                 h   g }| D ]  }t        |t              rt        j                  j	                  |      }t        |t        j                        r't
        j                  |      }|j                  |       st        |t
              r|j                  |       t        dt        |              |S )z
    Internal function to process legacy OCSP data into one or more
    :class:`.OCSPContainer`.

    :param ocsps:
        Legacy OCSP input data.
    :return:
        A list of :class:`.OCSPContainer` objects.
    zRocsps must be a list of byte strings or asn1crypto.ocsp.OCSPResponse objects, not )r   r   r   r   r   r   rv   extendr   r   r   )r   	new_ocspsocsp_extrs       r"   r   r     s     I eU#%%**51EeT../ ++E2DT"}-U#==Fu=M<NP  r$   )-abcr)   dataclassesr   r   typingr   r   r   r   r	   
asn1cryptor
   r   r   pyhanko_certvalidator._typesr   pyhanko_certvalidator.ltv.typesr   r   !pyhanko_certvalidator.policy_declr   r   r   __all__Enumr   r   ABCr   r?   r   rS   r^   r   rj   r   r   r   r   LegacyCompatCRLr   LegacyCompatOCSPr   r   r/   r$   r"   <module>r      s   
  !  ; ; ' ' 2 	(
TYY (
V $  $"*CGG "@ m+;</Xk2 /tK7H /4L7(#L7(#L7 L7 *	L7
 L7^-d$$%- $_Q$ _Q _QD $4# 4 4< s22L@A 1 1=@A 
?
#	,:$%	-r$   