
     h                        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
mZmZmZmZmZmZmZmZ d dlmZmZmZ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!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d d
l(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZD ddlEmFZF ddlGmHZHmIZImJZJmKZKmLZLmMZMmNZN ddlOmPZPmQZQmRZRmSZS g dZT ejU        eV          ZW edeL          ZXdeYfdZZdej[        dej\        fd Z]d!ej\        d"ej^        d#ej_        fd$Z`	 	 dZd%eja        dej[        d&ebd'ecd(eeQ         d)ee         d*eeYeYf         fd+Zdd,eje        d*e6fd-Zf	 	 	 	 	 	 d[d,eje        d.eec         d/ee         d0eeg         d1ee+         d2ee-         d3eeQ         d4eFd*e	ebef         fd5Zh	 d\dej[        d/ed4eFd6ee+         d2ee-         d*d7fd8Zieddddd9d,eje        d:eeX         d.eec         d/ee         d0eeg         d4eeF         d*eXfd;            Zjeddddd9d,eje        d.eec         d/ee         d0eeg         d4eeF         d*eLfd<            ZjeLdddddfd,eje        d.eec         d/ee         d0eeg         d4eeF         d3eeQ         d*eXfd=Zjd%eja        d*ee         fd>Zk	 d]d%eja        d@eYd*eeje                 fdAZld%eja        d*eec         fdBZmd%eja        dCee         d.ecfdDZn	 d\dEeje        d/ee         dFecd3eeQ         fdGZodHeejp                 dIej[        d/ed*eee/         eee%e$e#f                  f         fdJZqdKeejp                 dIej[        d/ee         dLej\        fdMZrddddde=js        dfdNeeceejt        eju        f         d,eje        dOee         dCee         dPee         d4eeF         d3eeQ         d*eMfdQZv edRdST          Zw edSU           G dV dWe
ew                               ZxdXeew         d*exew         fdYZydS )^    N)	dataclass)datetime)IOAny	AwaitableDictGenericIterableListOptionalTupleTypeTypeVarUnionoverload)cmscoretspx509)InvalidSignature)hashes)CancelableAsyncIteratorValidationContextfind_valid_path)DisallowedAlgorithmErrorExpiredErrorInvalidCertificateErrorPathBuildingErrorPathValidationErrorRevokedErrorValidationError)TimeSlideFailure)ValidationPath)PKIXValidationParams)ACValidationResultasync_validate_ac)
CMSExtractionErrorCMSStructuralErrorMultivaluedAttributeErrorNonexistentAttributeErrorSignedDataCertscheck_ess_certidextract_certificate_infoextract_signer_infofind_unique_cms_attributeget_pyca_cryptography_hash   )misc)lift_iterable_async   )AdESFailureAdESIndeterminate   )errors)KeyUsageConstraints)CAdESSignerAttributeAssertionsCertifiedAttributesClaimedAttributesRevocationDetailsSignatureStatusStandardCMSSignatureStatusTimestampSignatureStatus)DEFAULT_ALGORITHM_USAGE_POLICYCMSAlgorithmUsagePolicyextract_message_digestvalidate_raw)validate_sig_integrityasync_validate_cms_signaturecollect_timing_infovalidate_tst_signed_dataasync_validate_detached_cmscms_basic_validationcompute_signature_tst_digestextract_tst_dataextract_self_reported_tsextract_certs_for_validationcollect_signer_attr_statusvalidate_algorithm_protection
StatusType)boundv2c                 4   |rdnd}|rt           j        nt           j        }	 t          | |          }|                    |                                          S # t          $ r Y d S t          $ r(}t          j	        }t          j        d|          |d }~ww xY w)Nsigning_certificate_v2signing_certificatez3Wrong cardinality for signing certificate attributeades_subindication)r   SigningCertificateV2SigningCertificater/   loaddumpr*   r)   r6   NO_SIGNING_CERTIFICATE_FOUNDr8   SignatureValidationError)signed_attrsrS   	attr_nameclsvalueeerrs          _/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko/sign/validation/generic_cms.py_grab_signing_cert_attrrf   a   s     -/I((4II&(
D#
"
"c.DC),	BB xx

%%%$   tt$   <-A"
 
 
 	s   6A 
B&	B/#BBcertr_   c                     t          |d          }|t          |d          }|d S |d         d         }t          | |          s0t          j        }t	          j        d| j        j         d|          d S )	NT)rS   Fcertsr   zWSigning certificate attribute does not match selected signer's certificate for subject"z".rW   )rf   r,   r6   r]   r8   r^   subjecthuman_friendly)rg   r_   attrcertidrd   s        re   _check_signing_certificatern   w   s     #<D999D|&|>>>| ']1FD&)) 
<-2,2 2 2  #	
 
 
 	

 
    attrsclaimed_digest_algorithm_objclaimed_signature_algorithm_objc                 b   	 t          | d          }n*# t          $ r d}Y nt          $ r t          d          w xY w|n|d         j        }||j        k    rt          j        d          |d         j        }|t          j        d          ||j        k    rt          j        d          dS dS )	a+  
    Internal API to validate the CMS algorithm protection attribute
    defined in :rfc:`6211`, if present.

    :param attrs:
        A CMS attribute list.
    :param claimed_digest_algorithm_obj:
        The claimed (i.e. unprotected) digest algorithm value.
    :param claimed_signature_algorithm_obj:
        The claimed (i.e. unprotected) signature algorithm value.
    :raises errors.CMSStructuralError:
        if multiple CMS protection attributes are present
    :raises errors.CMSAlgorithmProtectionError:
        if a mismatch is detected
    cms_algorithm_protectionNz4Multiple CMS algorithm protection attributes presentdigest_algorithmzCDigest algorithm does not match CMS algorithm protection attribute.signature_algorithmz<CMS algorithm protection attribute not valid for signed datazFSignature mechanism does not match CMS algorithm protection attribute.)r/   r*   r)   r(   nativer8   CMSAlgorithmProtectionError)rp   rq   rr   cms_algid_protectionauth_digest_algorithmsigned_sig_algorithms         re   rP   rP      s#   *

8- 
  
 % $ $ $#$ 
 
 
 B
 
 	

 ' 45G H O $@$GGG4    4! 

 	  '4   "%D%KKK4(  ! (' LKs    ::signer_infoexpected_content_typeactual_digestalgorithm_usage_policy
time_indicreturnc           
         | d         }| d         }|d         j         }||                    |||j                  }	|	sCd|d         j          d}
|	j        |
d|	j         d	z  }
t	          j        |
|	j        du 
          |                    ||          }|sCd|d         j          d}
|j        |
d|j         d	z  }
t	          j        |
|j        du 
          | d         j         }| d         }|t          j	        u rd}d}|}nK| d         
                                }|                                }d}	 t          |||           nn# t          $ r*}t	          j        |j        t           j                  d}~wt          j        $ r*}t	          j        |j        t&          j                  d}~ww xY wt+          ||           	 t-          |d          }n5# t.          t0          f$ r! t	          j        dt           j                  w xY w|j         }||k    r&t	          j        d| d| t           j                  t3          |           }	 t5          ||||||||           d}n# t6          $ r d}Y nw xY w|||k    n|}||fS )ae  
    Validate the integrity of a signature for a particular signerInfo object
    inside a CMS signed data container.

    .. warning::
        This function does not do any trust checks, and is considered
        "dangerous" API because it is easy to misuse.

    :param signer_info:
        A :class:`cms.SignerInfo` object.
    :param cert:
        The signer's certificate.

        .. note::
            This function will not attempt to extract certificates from
            the signed data.
    :param expected_content_type:
        The expected value for the content type attribute (as a Python string,
        see :class:`cms.ContentType`).
    :param actual_digest:
        The actual digest to be matched to the message digest attribute.
    :param algorithm_usage_policy:
        Algorithm usage policy.
    :param time_indic:
        Time indication for the production of the signature.
    :return:
        A tuple of two booleans. The first indicates whether the provided
        digest matches the value in the signed attributes.
        The second indicates whether the signature of the digest is valid.
    rv   ru   	algorithmN)moment
public_keyzThe algorithm z, is not allowed by the current usage policy.z	 Reason: .)	permanent)r   	signaturer_   TF)rq   rr   rW   content_typezQContent type not found in signature, or multiple content-type attributes present.zContent type z did not match expected value )	prehashedalgorithm_policyr   )rw   signature_algorithm_allowedr   failure_reasonr8   r   not_allowed_afterdigest_algorithm_allowedr   VOIDuntagr\   rP   r(   r^   failure_messager5   FORMAT_FAILURErx   r6   GENERICrn   r/   r*   r)   rC   rD   r   )r|   rg   r}   r~   r   r   rv   digest_algorithm_objmd_algorithmsig_algo_allowedmsgdigest_algo_allowedr   signed_attrs_origembedded_digestr   signed_datar_   rc   r   validintacts                         re   rE   rE      s   N 6A6 ''9:'4;L)1MM
t N 
 
   		?!4[!A!H ? ? ?   .:E#3#BEEEE1/ATI    5MM  N 
 
 # 		?!5k!B!I ? ? ?  #1=H#6#EHHHH12DL    K(/I+6~+FDI%%	# #>288:: #''))		)-A0C    
 " 	 	 	1!k6P    1 	 	 	1! $5#<   	 	#4666		4n LL *+DE 	 	 	1&#.#=   	 $*0001+ + +(+ +#.#=    1==3!		
 		
 		
 		
    
 & 	((  5=sB   :E 
F8%E<<F8%F33F8G 2HI/ /I>=I>r   c                     	 t          |           }|j        }n.# t          $ r! t          j        dt
          j                  w xY wt          |           }|d         }t          ||           |S )a  
    Extract certificates from a CMS signed data object for validation purposes,
    identifying the signer's certificate in accordance with ETSI EN 319 102-1,
    5.2.3.4.

    :param signed_data:
        The CMS payload.
    :return:
        The extracted certificates.
    z,signer certificate not included in signaturerW   r_   )	r-   signer_certr'   r8   r^   r6   r]   r.   rn   )r   	cert_inforg   r|   r_   s        re   rN   rN   p  s     
,[99	$ 
 
 
-:0M
 
 
 	


 &k22K~.Lt\222s	    +A
raw_digestvalidation_contextstatus_kwargsvalidation_pathpkix_validation_paramsr   key_usage_settingsc                  K   t          |           }t          |           }	|	j        }
|	j        }d}|"|pt	          j        |j                  }|j        }|pt                      }|t          }|d         }|d         j
        }|d         d         j
        }| d         }|d         j
        }|at          |d                   }t          |          }t          j        |          }|                    |           |                                }	 t#          ||
||||          \  }}n;# t$          $ r.}t'          j        d	|j        z   t,          j        
          |d}~ww xY wdx}x}x}}|r	 |j                            |           |t5          |g          }n|j                            |
          }t;          |
||||           d{V }|j        }|j        }|j         p|j!        }|j"        }n?# tF          $ r2}tH          %                    d|           tL          j'        }Y d}~nd}~ww xY w|pi }|                    |||
||||||	  	         |S )z
    Perform basic validation of CMS and PKCS#7 signatures in isolation
    (i.e. integrity and trust checks).

    Internal API.
    Nrv   r   ru   encap_content_infor   content)r}   r~   r   r   zCMS structural error: rW   )r   pathsr   z&Processing error in validation processexc_info)	r   r   signing_certr   pkcs7_signature_mechanismtrust_problem_indicr   revocation_detailserror_time_horizon)(r.   rN   r   other_certsrB   lift_policyr   best_signature_timer   rA   rw   bytesr0   r   HashupdatefinalizerE   r(   r8   r^   r   r5   r   certificate_registryregister_multipler3   path_builderasync_build_paths_lazyvalidate_cert_usageerror_subindicrevo_detailssuccess_result
error_pathr   
ValueErrorloggererrorr6   !CERTIFICATE_CHAIN_GENERAL_FAILURE)r   r   r   r   r   r   r   r   r|   r   rg   r   r   rv   	mechanismr   ecir}   rawmd_specmdr   r   rc   ades_statuspathr   r   r   	op_results                                 re   rJ   rJ     s%     " &k22K,[99I D'KJ% &2"3  	 (;
+B/@/B/B95@6 $K07I12;?FL
*
+C/6C	N##,\::[!!
		#[[]]
."7$#3!
 
 
    -$q'88*9
 
 
 	 >BAKA$A(: N	N3EE  
 *+_,=>>*7NN  2"#5'=        I $2K$1L+Cy/CD!*!= 	N 	N 	NLLAALNNN+MKKKKKK	N "'RM!"+''-  
 
 
 s1   D( (
E 2)EE .BG3 3
H/=(H**H/r   z,CertvalidatorOperationResult[ValidationPath]c                 l    K   dt           f fd}t           |                       d{V S )zE
    Low-level certificate validation routine.
    Internal API.
    r   c                  d   K                                    t                      d {V S )N)r   r   )validater   )rg   r   r   r   r   s   re   _checkz#validate_cert_usage.<locals>._check  s\      ##D)))$1#9	
 
 
 
 
 
 
 
 
 	
ro   N)r#   handle_certvalidator_errors)rg   r   r   r   r   r   s   ````` re   r   r     sl      
. 
 
 
 
 
 
 
 
 
 
 -VVXX666666666ro   )r   r   r   r   
status_clsc                
   K   d S N )r   r   r   r   r   r   s         re   rF   rF     s       Cro   c                
   K   d S r   r   )r   r   r   r   r   s        re   rF   rF   (  s       Cro   c                 v   K   |                     |          }t          | |||||           d{V } |di |S )a  
    Validate a CMS signature (i.e. a ``SignedData`` object).

    :param signed_data:
        The :class:`.asn1crypto.cms.SignedData` object to validate.
    :param status_cls:
        Status class to use for the validation result.
    :param raw_digest:
        Raw digest, computed from context.
    :param validation_context:
        Validation context to validate the signer's certificate.
    :param status_kwargs:
        Other keyword arguments to pass to the ``status_class`` when reporting
        validation results.
    :param key_usage_settings:
        A :class:`.KeyUsageConstraints` object specifying which key usages
        must or must not be present in the signer's certificate.
    :param algorithm_policy:
        The algorithm usage policy for the signature validation.

        .. warning::
            This is distinct from the algorithm usage policy used for
            certificate validation, but the latter will be used as a fallback
            if this parameter is not specified.

            It is nonetheless recommended to align both policies unless
            there is a clear reason to do otherwise.
    :return:
        A :class:`.SignatureStatus` object (or an instance of a proper subclass)
    )r   r   Nr   )default_usage_constraintsrJ   )r   r   r   r   r   r   r   eff_key_usage_settingss           re   rF   rF   4  s      N (AA  /1)        M :&&&&&ro   c                 r    	 | d         }t          |d          }|j        S # t          t          f$ r Y dS w xY w)a  
    Extract self-reported timestamp (from the ``signingTime`` attribute)

    Internal API.

    :param signer_info:
        A ``SignerInfo`` value.
    :return:
        The value of the ``signingTime`` attribute as a ``datetime``, or
        ``None``.
    r_   signing_timeN)r/   rw   r*   r)   )r|   sasts      re   rM   rM   j  sP    (&r>::y%'@A   tts   ! 66Fsignedc                     	 |r| d         }t          |d          }n| d         }t          |d          }|d         }|S # t          t          f$ r Y dS w xY w)a  
    Extract signed data associated with a timestamp token.

    Internal API.

    :param signer_info:
        A ``SignerInfo`` value.
    :param signed:
        If ``True``, look for a content timestamp (among the signed
        attributes), else look for a signature timestamp (among the unsigned
        attributes).
    :return:
        The ``SignedData`` value found, or ``None``.
    r_   content_time_stampunsigned_attrssignature_time_stamp_tokenr   N)r/   r*   r)   )r|   r   r   tstuatst_signed_datas         re   rL   rL   ~  s~    "
 	N^,B+B0DEECC-.B+B0LMMCi.%'@A   tts   <? AAc                 6   t          |           }|dS |d         }|d         j        d         }|d         d         j        }| d         j        }t          |          }t	          j        |          }|                    |           |                                S )a.  
    Compute the digest of the signature according to the message imprint
    algorithm information in a signature timestamp token.

    Internal API.

    :param signer_info:
        A ``SignerInfo`` value.
    :return:
        The computed digest, or ``None`` if there is no signature timestamp.
    Nr   r   message_imprinthash_algorithmr   r   )rL   parsedrw   r0   r   r   r   r   )r|   tst_datar   mitst_md_algorithmsignature_bytestst_md_specr   s           re   rK   rK     s      ,,Ht
'
(C	Y	0	1B*+K8?!+.5O,-=>>K	[	!	!BIIo;;==ro   ts_validation_contextc                 N  K   i }t          |           }|||d<   t          | d          }|;t          |           }|J t          |||           d{V }t	          d	i |}||d<   t          | d          }	|	)t          |	||           d{V }
t	          d	i |
}||d<   |S )
a  
    Collect and validate timing information in a ``SignerInfo`` value.
    This includes the ``signingTime`` attribute, content timestamp information
    and signature timestamp information.

    :param signer_info:
        A ``SignerInfo`` value.
    :param ts_validation_context:
        The timestamp validation context to validate against.
    :param raw_digest:
        The raw external message digest bytes (only relevant for the
        validation of the content timestamp token, if there is one)
    Nsigner_reported_dtF)r   timestamp_validityT)expected_tst_imprintcontent_timestamp_validityr   )rM   rL   rK   rH   r@   )r|   r   r   r   r   r   tst_signature_digesttst_validity_kwargstst_validitycontent_tst_signed_datacontent_tst_validity_kwargscontent_tst_validitys               re   rG   rG     s@     & %'M 2+>>%.@*+&{5AAAO";KHH#///$<! %
 %
 
 
 
 
 
 

 0FF2EFF.:*+.{4HHH*,D#!!+-
 -
 -
 '
 '
 '
 '
 '
 '
#
  8  
  
) 
  
 7K23ro   r   r   c                   K   d}| d         d         }t          |t          j                  r|j        }t          |t          j                  s t          j        dt          j	                  |d         j
        }t          j                    }t          | |d|i||           d{V }|d	         d
         j
        }	||	k    rJt                              d|	                                 d|                                 d           d|d<   |S )a  
    Validate the ``SignedData`` of a time stamp token.

    :param tst_signed_data:
        The ``SignedData`` value to validate; must encapsulate a ``TSTInfo``
        value.
    :param validation_context:
        The validation context to validate against.
    :param expected_tst_imprint:
        The expected message imprint value that should be contained in
        the encapsulated ``TSTInfo``.
    :param algorithm_policy:
        The algorithm usage policy for the signature validation.

        .. warning::
            This is distinct from the algorithm usage policy used for
            certificate validation, but the latter will be used as a fallback
            if this parameter is not specified.

            It is nonetheless recommended to align both policies unless
            there is a clear reason to do otherwise.
    :return:
        Keyword arguments for a :class:`.TimeStampSignatureStatus`.
    Nr   r   z'SignedData does not encapsulate TSTInforW   gen_time	timestamp)r   r   r   r   r   hashed_messagezTimestamp token imprint is z, but expected r   Fr   )
isinstancer   ParsableOctetStringr   r   TSTInfor8   r^   r5   r   rw   r@   r   rJ   r   warninghex)
r   r   r   r   tst_infotst_info_bytesr   ku_settingsr   tst_imprints
             re   rH   rH     sV     > H$%9:9EN.$":;; )!(h,, 
-5*9
 
 
 	
 $+I*DFFK.-"I.&)        M ,-.>?FK{**-+//*;*; - -#''))- - -	
 	
 	
 #(hro   acsr   c                   K   fd| D             }g }g }t          j        |          D ]R}	 |                    | d {V            # t          t          t
          f$ r} |j        |           Y d }~Kd }~ww xY w||fS )Nc                 4    g | ]}t          |           S ))holder_cert)r&   ).0acr   r   s     re   
<listcomp>z+process_certified_attrs.<locals>.<listcomp>:  s9        	"0kJJJ  ro   )asyncioas_completedappendr   r   r   )r
  r   r   jobsresultsr8   jobrc   s    ``     re   process_certified_attrsr  0  s            D GF#D))  	NN999999%%%%#
 	 	 	
 FM!	 F?s   AA<"A77A<sd_attr_certificatessd_signed_attrsc                   K   	 t          |d          }nM# t          $ r d }Y n?t          $ r3}t          j        t          |          t          j                  |d }~ww xY wi }d }d }||d         }	t          j	        t          |	t          j                  s|	nd          }
|d         }d}t          |t          j                  sJd |D             }t          |          t          |          k    }|t          |||          }| d {V \  }}|t          j        |          }nd }|p t          |d         t          j                   }||rt"                              d	           t'          |
|||
          |d<   |dt          | ||           d {V \  }}|r|                    |           |r|                    |           t          j        |          |d<   ||d<   |S )Nsigner_attributes_v2rW   claimed_attributesr   certified_attributes_v2Fc                 2    g | ]}|j         d k    |j        S )	attr_cert)namechosen)r  rl   s     re   r  z.collect_signer_attr_status.<locals>.<listcomp>r  s1       9++ +++ro   signed_assertionszCAdES signer attributes with externally certified assertions for which no validation method is available. This may affect signature semantics in unexpected ways.)claimed_attrscertified_attrsac_validation_errsunknown_attrs_presentcades_signer_attrsac_attrsr%  )r/   r*   r)   r8   r^   strr5   r   r<   from_iterabler  r   Voidlenr  r;   from_resultsr   r  r:   extend)r  r   r   r  signer_attrsrc   resultcades_ac_resultscades_ac_errorsclaimed_asn1claimedcertified_asn1unknown_cert_attrs	cades_acsval_job	certifiedunknown_attrs
ac_results	ac_errorss                      re   rO   rO   L  s     
03
 
 %   $   -FF{'A
 
 
	  FO#$89 $1 *< C CKLL
 
 &&?@".$)44 	B *  I "%Y3~3F3F!F!-1& 
 ;BMMMMMM1 / ' ,89IJJIII
 + 
*,-ty3
 3
 /
 )m)NN:   (F!%."/	(
 (
 (
#$ % '> +/A'
 '
 !
 !
 !
 !
 !
 !

I
  	0./// 	._---0=jIIz'0#$Ms    A	A.AA
input_datasigner_validation_contextac_validation_contextc	           	      |  K   ||}t          |          }	|	d         d         j        }
t          j        t	          |
                    }t          | t                    r|                    |            nvt          | t          j	        t          j
        f          r)|                    t          | d                              n't          |          }t          j        || ||           |                                }t          |	||           d{V }t!          j        |          }t%          ||||||           d{V }t'          |          }||j                            |j                   |                    t/          |j        |j        ||	d         	           d{V            t!          d
i |S )a  
    .. versionadded: 0.9.0

    .. versionchanged: 0.11.0
        Added ``ac_validation_context`` param.

    Validate a detached CMS signature.

    :param input_data:
        The input data to sign. This can be either a :class:`bytes` object,
        a file-like object or a :class:`cms.ContentInfo` /
        :class:`cms.EncapsulatedContentInfo` object.

        If a CMS content info object is passed in, the `content` field
        will be extracted.
    :param signed_data:
        The :class:`cms.SignedData` object containing the signature to verify.
    :param signer_validation_context:
        Validation context to use to verify the signer certificate's trust.
    :param ts_validation_context:
        Validation context to use to verify the TSA certificate's trust, if
        a timestamp token is present.
        By default, the same validation context as that of the signer is used.
    :param ac_validation_context:
        Validation context to use to validate attribute certificates.
        If not supplied, no AC validation will be performed.

        .. note::
            :rfc:`5755` requires attribute authority trust roots to be specified
            explicitly; hence why there's no default.
    :param algorithm_policy:
        The algorithm usage policy for the signature validation.

        .. warning::
            This is distinct from the algorithm usage policy used for
            certificate validation, but the latter will be used as a fallback
            if this parameter is not specified.

            It is nonetheless recommended to align both policies unless
            there is a clear reason to do otherwise.
    :param key_usage_settings:
        Key usage parameters for the signer.
    :param chunk_size:
        Chunk size to use when consuming input data.
    :param max_read:
        Maximal number of bytes to read from the input stream.
    :return:
        A description of the signature's status.
    Nru   r   r   )max_read)r   r   )r   r   r   r   r   r_   )r  r   r   r  r   )r.   rw   r   r   r0   r  r   r   r   ContentInfoEncapsulatedContentInfo	bytearrayr2   chunked_digestr   rG   r?   r   rJ   r-   r   r   r   rO   attribute_certsr   )r=  r   r>  r   r?  r   r   
chunk_sizerA  r|   ru   htemp_bufdigest_bytesr   r   s                   re   rI   rI     s0     z $ 9%k22K"#56{CJ./?@@AAA*e$$ H		J#2M N	O	O H	z),--....Z((Hj!hGGGG::<<L-3        M
 4M  /4#-)        M )55I(2DD!	
 	
 	
 (!*!:!-4'7	
 
 
 	
 	
 	
 	
 	
 	
   &66666ro   
ResultTypeT)	covariant)frozenc                       e Zd ZU dZee         ed<   dZee         ed<   dZ	ee
         ed<   dZee         ed<   dZee         ed<   dS )CertvalidatorOperationResultzB
    Internal class to inspect error data from certvalidator.
    r   Nr   r   r   r   )__name__
__module____qualname____doc__r   rK  __annotations__r   r=   r   r   r   r#   r   r6   r   ro   re   rO  rO    s           Z((((04L(,-444-1*111+/J(///26NH./66666ro   rO  coroc                   K   d}dx}}	 t          |  d{V           S # t          $ r8}t                              |j        |           t
          j        }Y d}~n{d}~wt          $ r8}t                              |j        |           t
          j        }Y d}~n;d}~wt          $ rZ}t                              |j        |           |j
        }|j        t
          j        }nt
          j        }|j        }Y d}~nd}~wt          $ r}|j
        }t                              |j                   |j        }|j        rt
          j        }nX|j        r)t
          j        }t)          d|j        |j                  }n(t
          j        }t)          d|j        |j                  }Y d}~n-d}~wt.          $ r2}t                              d|           t
          j        }Y d}~nd}~wt2          $ r^}|j
        }t                              |j                   |j        }|j        s|j        rt
          j        }nt
          j        }Y d}~nd}~wt8          $ r>}|j
        }t                              |j        |           t
          j        }Y d}~nGd}~wt:          $ r7}t                              |j        |           t
          j        }Y d}~nd}~ww xY wt          d||||          S )	z
    Internal error handling function that maps certvalidator errors
    to AdES status indications.

    :param coro:
    :return:
    N)r   r   F)
ca_revokedrevocation_daterevocation_reasonTzFailed to build path)r   r   r   r   r   )rO  r   r   r  failure_msgr6   CHAIN_CONSTRAINTS_FAILUREr"   NO_POEr   original_pathbanned_sinceCRYPTO_CONSTRAINTS_FAILURE!CRYPTO_CONSTRAINTS_FAILURE_NO_POEr    revocation_dtis_side_validationr   
is_ee_certREVOKED_NO_POEr=   reasonREVOKED_CA_NO_POEr   NO_CERTIFICATE_CHAIN_FOUNDr   
expired_dtOUT_OF_BOUNDS_NO_POEr   r!   )rU  time_horizonr   r   rc   r   s         re   r   r   ,  s<      (,LL4@J+::::::FFFF" B B Bq}q111'A / / /q}q111'.# * * *q}q111 >!+FKK ,MK>L   q}%%% 	+MKK\ 	+:K,  !"#(  LL ,=K, !"#(  L
  C C C-:::'B N N Nq}%%%|# 	N 	N
 ,@KK+MK B B Bq}q111'A J J Jq}q111'IJ (!'"   sk     
K-AK*-BK*AC??KBF++K8(G%%K2AIK4JK-KK)NN)NNNNNNr   )F)zr  loggingdataclassesr   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   
asn1cryptor   r   r   r   cryptography.exceptionsr   cryptography.hazmat.primitivesr   pyhanko_certvalidatorr   r   r   pyhanko_certvalidator.errorsr   r   r   r   r   r    r!    pyhanko_certvalidator.ltv.errorsr"   pyhanko_certvalidator.pathr#   !pyhanko_certvalidator.policy_declr$   pyhanko_certvalidator.validater%   r&   pyhanko.sign.generalr'   r(   r)   r*   r+   r,   r-   r.   r/   r0   	pdf_utilsr2   pdf_utils.miscr3   ades.reportr5   r6    r8   settingsr9   statusr:   r;   r<   r=   r>   r?   r@   utilsrA   rB   rC   rD   __all__	getLoggerrP  r   rQ   boolrf   CertificateCMSAttributesrn   DigestAlgorithmSignedDigestAlgorithmrP   
SignerInfor)  r   rE   
SignedDatarN   dictrJ   r   rF   rM   rL   rK   rG   rH   AttributeCertificateV2r  rO   DEFAULT_CHUNK_SIZErB  rC  rI   rK  rO  r   r   ro   re   <module>r     s
     ! ! ! ! ! !                                     , + + + + + + + + + + + 4 4 4 4 4 4 1 1 1 1 1 1         
                  > = = = = = 5 5 5 5 5 5 B B B B B B P P P P P P P P                              1 1 1 1 1 1 8 8 8 8 8 8 8 8       ) ) ) ) ) )                               
	8	$	$W\999
d    ,



*-*;
 
 
 
833"%"53 &)%>3 3 3 3v AE%)d dd

d d 	d
 %%<=d "d 4:d d d dN   B #'6:$(04=A:>p ppp !!23p D>	p
 n-p %%9:p 67p ,p 
#s(^p p p pp >B7 7

7)7 ,7 #>2	7
 %%9:7 47 7 7 72 

 #'6:$(8<	 	 		 Z 	 		
 !!23	 D>	 !!45	 	 	 	 
	 
 #'6:$(8<    !!23	
 D> !!45    
 "&6:$(8<:>3' 3'3' 3' !!23	3'
 D>3' !!453' 673' 3' 3' 3' 3'l#. Xh=O    * 16 )-cn   <e_   B22#$562 2 2 2 2r ;?	; ;^; !23;  ; 67	; ; ; ;|	#,	-! * 	!#46MMN	   8b"3#=>b!b !!23b &	b b b bP >B9=9=8<:>&h7 h7eR#2MMNh7h7  ((9:h7 $$56	h7
 $$56h7 !!45h7 67h7  h7 h7 h7 h7V W\T222
 $	7 	7 	7 	7 	77:#6 	7 	7 	7T
J
T!*-T T T T T Tro   