
     h                        d dl Z d dlmZ d dl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 dd	lmZmZmZ dd
lmZ g dZ G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de j                  Z G d de j                  ZdS )    N)datetime)IterableOptional)algoscmscore)pdf)tspx509)hashes   )as_signing_certificate_v2get_pyca_cryptography_hashsimple_cms_attribute)TimeStamper)SignedAttributeProviderSpecUnsignedAttributeProviderSpecCMSAttributeProviderSigningTimeProviderSigningCertificateV2ProviderAdobeRevinfoProviderCMSAlgorithmProtectionProviderTSTProviderc                   L    e Zd ZU dZeed<   	 ddZddeej	                 fdZ
dS )	r   zB
    Base class to provide asynchronous CMS attribute values.
    attribute_typeFc                    K   t           )a  
        Build the attribute value asynchronously.

        :param dry_run:
            ``True`` if the signer is operating in dry-run (size estimation)
            mode.
        :return:
            An attribute value appropriate for the attribute type.
        NotImplementedErrorselfdry_runs     S/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko/sign/attributes.pybuild_attr_valuez%CMSAttributeProvider.build_attr_value(   s       "!    returnc                 p   K   |                      |           d {V }|t          | j        |          S d S )N)r!   )r#   r   r   )r    r!   values      r"   get_attributez"CMSAttributeProvider.get_attribute4   sL      ++G+<<<<<<<<'(;UCCC4r$   NF)__name__
__module____qualname____doc__str__annotations__r#   r   r   CMSAttributer(    r$   r"   r   r      so           

" 
" 
" 
" HS=M4N      r$   r   c                   P    e Zd ZU dZdZeed<   dej        fdZ	d
de
j        fdZd	S )r   z
    Provide a value for the signing-certificate-v2 attribute.

    :param signing_cert:
        Certificate containing the signer's public key.
    signing_certificate_v2r   signing_certc                     || _         d S N)r4   )r    r4   s     r"   __init__z%SigningCertificateV2Provider.__init__F   s    (r$   Fr%   c                 .   K   t          | j                  S r6   )r   r4   r   s     r"   r#   z-SigningCertificateV2Provider.build_attr_valueI   s      ():;;;r$   Nr)   )r*   r+   r,   r-   r   r.   r/   r   Certificater7   r
   SigningCertificateV2r#   r1   r$   r"   r   r   <   ss           3NC222)T%5 ) ) ) )< <s7O < < < < < <r$   r   c                   F    e Zd ZU dZdZeed<   defdZd
de	j
        fdZd	S )r   z
    Provide a value for the signing-time attribute (i.e. an otherwise
    unauthenticated timestamp).

    :param timestamp:
        Datetime object to include.
    signing_timer   	timestampc                     || _         d S r6   )r=   )r    r=   s     r"   r7   zSigningTimeProvider.__init__X   s    "r$   Fr%   c                 `   K   t          j        dt          j        | j                  i          S )Nutc_time)r   Timer   UTCTimer=   r   s     r"   r#   z$SigningTimeProvider.build_attr_value[   s'      xT\$.%A%ABCCCr$   Nr)   )r*   r+   r,   r-   r   r.   r/   r   r7   r   rA   r#   r1   r$   r"   r   r   M   sw           )NC(((#( # # # #D Dsx D D D D D Dr$   r   c                   ^    e Zd ZU dZdZeed<   dej        fdZ		 d
de
ej                 fdZd	S )r   z
    Yield Adobe-style revocation information for inclusion into a CMS
    object.

    :param value:
        A (pre-formatted) RevocationInfoArchival object.
    adobe_revocation_info_archivalr   r'   c                     || _         d S r6   r'   )r    r'   s     r"   r7   zAdobeRevinfoProvider.__init__p   s    


r$   Fr%   c                    K   | j         S r6   rF   r   s     r"   r#   z%AdobeRevinfoProvider.build_attr_values   s       zr$   Nr)   )r*   r+   r,   r-   r   r.   r/   asn1_pdfRevocationInfoArchivalr7   r   r#   r1   r$   r"   r   r   e   s~           ;NC:::h=      	(1	2     r$   r   c                   R    e Zd ZU dZeed<   dedej        fdZ	 d
de	j
        fdZd	S )r   cms_algorithm_protectionr   digest_algosignature_algoc                 "    || _         || _        d S r6   )rL   rM   )r    rL   rM   s      r"   r7   z'CMSAlgorithmProtectionProvider.__init__|   s     ',r$   Fr%   c                 p   K   t          j        t          j        d| j        i          | j        d          S )N	algorithm)digest_algorithmsignature_algorithm)r   CMSAlgorithmProtectionr   DigestAlgorithmrL   rM   r   s     r"   r#   z/CMSAlgorithmProtectionProvider.build_attr_value   sJ       )$)$9 $"23% % (,':	 
 
 	
r$   Nr)   )r*   r+   r,   r   r.   r/   r   SignedDigestAlgorithmr7   r   rS   r#   r1   r$   r"   r   r   y   sv         4NC444--050K- - - - 

 

		#

 

 

 

 

 

r$   r   c            	       D    e Zd Z	 	 ddedededefdZddej        fd	Z	d
S )r   signature_time_stamp_tokenFrQ   
data_to_tstimestamper	attr_typec                 L    || _         || _        || _        || _        || _        d S r6   )r   rQ   rY   data	prehashed)r    rQ   rX   rY   rZ   r]   s         r"   r7   zTSTProvider.__init__   s.     ( 0&	"r$   r%   c                 T  K   | j         }| j        r| j        }nQt          |          }t	          j        |          }|                    | j                   |                                }|r| j        	                    |          }n| j        
                    ||          }| d {V S r6   )rQ   r]   r\   r   r   HashupdatefinalizerY   async_dummy_responseasync_timestamp)r    r!   rQ   digestmd_specmdts_coros          r"   r#   zTSTProvider.build_attr_value   s      0> 	#YFF01ABBGW%%BIIdi   [[]]F 	Q&;;<LMMGG&66v?OPPG}}}}}}r$   N)rW   Fr)   )
r*   r+   r,   r.   bytesr   r7   r   ContentInfor#   r1   r$   r"   r   r      s}         6# ## # !	#
 # # # # s      r$   r   c                   2    e Zd ZdZdededee         fdZdS )r   z
    .. versionadded:: 0.14.0

    Interface for setting up signed attributes, independently of the
    :class:`~pyhanko.sign.signers.pdf_cms.Signer` hierarchy.
    data_digestrQ   r%   c                     t           )z
        Lazily set up signed attribute providers.

        :param data_digest:
            The digest of the data to be signed.
        :param digest_algorithm:
            The digest algorithm used.
        r   )r    rk   rQ   s      r"   signed_attr_providersz1SignedAttributeProviderSpec.signed_attr_providers   s
     "!r$   N)	r*   r+   r,   r-   rh   r.   r   r   rm   r1   r$   r"   r   r      sP         " "47"	&	'" " " " " "r$   r   c            	       @    e Zd ZdZdedej        dedee	         fdZ
dS )r   z
    .. versionadded:: 0.14.0

    Interface for setting up unsigned attributes, independently of the
    :class:`~pyhanko.sign.signers.pdf_cms.Signer` hierarchy.
    	signaturesigned_attrsrQ   r%   c                     t           )a>  
        Lazily set up unsigned attribute providers.

        :param signature:
            The signature computed over the signed attributes.
        :param signed_attrs:
            Signed attributes over which the signature was taken.
        :param digest_algorithm:
            The digest algorithm used.
        r   )r    ro   rp   rQ   s       r"   unsigned_attr_providersz5UnsignedAttributeProviderSpec.unsigned_attr_providers   s
      "!r$   N)r*   r+   r,   r-   rh   r   CMSAttributesr.   r   r   rr   r1   r$   r"   r   r      sa         "" '" 	"
 
&	'" " " " " "r$   r   )abcr   typingr   r   
asn1cryptor   r   r   r	   rH   r
   r   cryptography.hazmat.primitivesr   generalr   r   r   
timestampsr   __all__r   r   r   r   r   r   ABCr   r   r1   r$   r"   <module>r|      sR   



       % % % % % % % % ' ' ' ' ' ' ' ' ' ' & & & & & &                 1 1 1 1 1 1         
 $ # # # # #	 	 	       >< < < < <#7 < < <"D D D D D. D D D0    /   (
 
 
 
 
%9 
 
 
,    &   >" " " " "#' " " "," " " " "CG " " " " "r$   