
     h6              
          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 g d	Z G d
 dej                  Z ed           G d d                      Z G d dee j                  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j!                 fdZ" ed           G d de                      Z# ed           G d  d!e                      Z$e
e%ej&        e$f         Z'e
e%ej(        e#f         Z)d"ee'         dee$         fd#Z*d$ee)         dee#         fd%Z+dS )&    N)	dataclass)datetime)IterableListOptionalTypeVarUnion)algoscrlocsp)	type_name)IssuedItemContainerValidationTimingParams)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dS )r   zz
    Description of whether a piece of revocation information
    is considered usable in the circumstances provided.
    returnc                 6    | 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    b/var/www/html/Sam_Eipo/venv/lib/python3.11/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      s         
 
B DIKKE dikkG dikkG
 	
T 	
 	
 	
 X	
 	
 	
r#   r   T)frozenc                   :    e Zd ZU dZeed<   	 dZee         ed<   dS )r   z`
    Usability rating and cutoff date for a particular piece of
    revocation information.
    ratingNlast_usable_at)	r$   r%   r&   r'   r   __annotations__r2   r   r   r.   r#   r!   r   r   J   sJ          
 #""" *.NHX&--- r#   r   c                   X    e Zd ZdZdededefdZede	e
j                 fd            ZdS )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    r5   r6   s      r!   	usable_atzRevinfoContainer.usable_atb   s
     "!r#   c                     t           )z
        Extract the signature mechanism used to guarantee the authenticity
        of the revocation information, if applicable.
        r8   r   s    r!   revinfo_sig_mechanism_usedz+RevinfoContainer.revinfo_sig_mechanism_usedr   s
     "!r#   N)r$   r%   r&   r'   r   r   r   r:   r,   r   r
   SignedDigestAlgorithmr<   r.   r#   r!   r   r   ]   sz         "("9O"	" " " "  "	%-	." " " X" " "r#   r   RevInfoType)boundlstr   c                 <    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)rB   dts     r!   _keyz!sort_freshest_first.<locals>._key   s    $ ~r!!r#   T)keyreverse)r   sorted)r@   rG   s     r!   r   r      s5    "( " " " " #4....r#   c                 Z    | j         }||||k    r||z
  }|t          |          |z   }|S rD   )	freshnessabs)r5   this_updatenext_updatetime_tolerancefreshness_deltas        r!   _freshness_deltarR      sH    &O"{k'A'A)K7O"o..?r#   rN   rO   r5   r6   c                 P   | 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 n|j        t          j        k    rUt          || ||          }|t          t          j                  S | ||z
  k     rt          t          j
        | |z             S n|j        t          j        k    rn|t          t          j                  S |j        }|s"|| |z
  k     rt          t          j                  S |||z   k    rt          t          j
        ||z             S nt          t          t          j                  S )N)r2   )r   r   r+   validation_timerP   freshness_req_typer   TIME_AFTER_SIGNATURErR   best_signature_timer*   MAX_DIFF_REVOCATION_VALIDATIONDEFAULTretroactive_revinfor   r9   r   )	rN   rO   r5   r6   rT   rP   rQ   signature_poe_timeretroactives	            r!   _judge_revinfor]      s     6 >???#3O"1N  $4$III +Kn
 
 "#$:$BCCC*>++o==#&,*_<    > 	!:	; 	; +Kn
 
 "#$:$BCCC
 ?:::#&,*_<    ;
 
	"&6&>	>	> #$:$BCCC0 	D~1MMM#$:$BCCC[>999#&,*^;    : "!25666r#   c                 |    | d         j         }|dk    rd S | d         }|d         j         dk    rd S |d         j        S )Nresponse_status
successfulresponse_bytesresponse_typebasic_ocsp_responseresponse)nativeparsed)ocsp_responsestatusra   s      r!   _extract_basic_ocsp_responseri      sT     ,-4Ft"#34No&-1FFFt*%,,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j                 fd            ZdS )r   z)
    Container for an OCSP response.
    ocsp_response_datar   indexrg   r   c                     t                    }|g S |d         }fdt          t          |d                             D             S )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.
        Ntbs_response_datac                 2    g | ]}t          |           S ))rk   rl   )r   ).0ixrg   s     r!   
<listcomp>z,OCSPContainer.load_multi.<locals>.<listcomp>$  s6     
 
 
 ]"EEE
 
 
r#   	responses)ri   rangelen)clsrg   rc   tbs_responses    `  r!   
load_multizOCSPContainer.load_multi  si    " ;=II&I*+>?
 
 
 
C[ 9::;;
 
 
 	
r#   c                 L    |                                  }|d S |d         j        S )NrN   )extract_single_responsere   )r    cert_responses     r!   rE   zOCSPContainer.issuance_date)  s,    4466 4]+22r#   r5   r6   c                     |                                  }|t          t          j                  S |d         j        }|d         j        }t          ||||          S )NrN   rO   r5   r6   )rz   r   r   r+   re   r]   )r    r5   r6   r{   rN   rO   s         r!   r:   zOCSPContainer.usable_at1  sj     4466 #$:$BCCC#M29#M2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).
        )ri   rk   r   s    r!   extract_basic_ocsp_responsez)OCSPContainer.extract_basic_ocsp_responseA  s     ,D,CDDDr#   c                     |                                  }|dS |d         }t          |d                   | j        k    rdS |d         | j                 S )z^
        Extract the unique ``SingleResponse`` value identified by the
        index.
        Nrn   rs   )r   ru   rl   )r    rc   rw   s      r!   rz   z%OCSPContainer.extract_single_responseI  s]     #>>@@&4*+>?|K())TZ774K(44r#   c                 B    |                                  }|d n|d         S Nsignature_algorithm)r   )r    
basic_resps     r!   r<   z(OCSPContainer.revinfo_sig_mechanism_usedX  s*     5577
!)ttz:O/PPr#   N)r$   r%   r&   r'   r   OCSPResponser3   rl   intclassmethodr   rx   r,   r   r   rE   r   r   r   r:   BasicOCSPResponser   SingleResponserz   r
   r=   r<   r.   r#   r!   r   r      s\          )))) E3NNN
 
 -
	o	
 
 
 [
4 3x1 3 3 3 X3
(
9O
	
 
 
 
 EXd6L-M E E E E5$2E)F 5 5 5 5 Q	%-	.Q Q Q X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d	S )
r   z<
    Container for a certificate revocation list (CRL).
    crl_datar5   r6   r   c                 v    | j         d         }|d         j        }|d         j        }t          ||||          S )Ntbs_cert_listrN   rO   r}   )r   re   r]   )r    r5   r6   r   rN   rO   s         r!   r:   zCRLContainer.usable_atk  sJ     o6#M29#M29V=
 
 
 	
r#   c                 6    | j         d         }|d         j        S )Nr   rN   )r   re   )r    r   s     r!   rE   zCRLContainer.issuance_dateu  s    o6]+22r#   c                     | j         d         S r   )r   r   s    r!   r<   z'CRLContainer.revinfo_sig_mechanism_usedz  s    }233r#   N)r$   r%   r&   r'   r   CertificateListr3   r   r   r   r:   r,   r   r   rE   r
   r=   r<   r.   r#   r!   r   r   `  s           !!!!
(
9O
	
 
 
 
 3x1 3 3 3 X3 4E,G 4 4 4 X4 4 4r#   r   crlsc                 `   g }| D ]}t          |t                    rt          j                            |          }t          |t          j                  rt          |          }t          |t
                    r|                    |           t          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"" 	2&++D11DdC/00 	&%%DdL)) 	OOD!!!!Q?HQ Q   Or#   ocspsc                    g }| D ]}t          |t                    rt          j                            |          }t          |t          j                  r0t
                              |          }|                    |           t          |t
                    r|                    |           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   rx   extendr   r   r   )r   	new_ocspsocsp_extrs       r!   r   r     s     I  eU## 	2%**511EeT.// 		 ++E22DT""""}-- 	U####P=Fu=M=MP 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   __all__Enumr   r   ABCr   r>   r   rR   r]   r   ri   r   r   r   r   LegacyCompatCRLr   LegacyCompatOCSPr   r   r.   r#   r!   <module>r      s   



  ! ! ! ! ! !       ; ; ; ; ; ; ; ; ; ; ; ; ; ; ' ' ' ' ' ' ' ' ' ' 2 2 2 2 2 2              
	 	 	(
 (
 (
 (
 (
TY (
 (
 (
V $       $" " " " "*CG " " "@ gm+;<<</Xk2 /tK7H / / / /4  G7(#G7(#G7 G7 *	G7
 G7 G7 G7 G7T-d$%- - - - $_Q _Q _Q _Q _Q$ _Q _Q _QD $4 4 4 4 4# 4 4 4< s2L@A 1=@A 
?
#	,   :$%	-     r#   