
    Wwg                     b   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 j8                        Z G d de j8                        Zy)    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                   N    e Zd ZU dZeed<   	 ddZddeej                     fdZ
y)r   zB
    Base class to provide asynchronous CMS attribute values.
    attribute_typec                    K   t         w)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     N/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko/sign/attributes.pybuild_attr_valuez%CMSAttributeProvider.build_attr_value(   s      "!s   	returnc                 t   K   | j                  |       d {   }|t        | j                  |      S y 7 w)N)r!   )r#   r   r   )r    r!   values      r"   get_attributez"CMSAttributeProvider.get_attribute4   s=     ++G+<<'(;(;UCC	 =s   868NF)__name__
__module____qualname____doc__str__annotations__r#   r   r   CMSAttributer'        r"   r   r      s0     

"HS=M=M4N r1   r   c                   b    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y)
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                     || _         y N)r4   )r    r4   s     r"   __init__z%SigningCertificateV2Provider.__init__F   s
    (r1   r$   c                 4   K   t        | j                        S wr6   )r   r4   r   s     r"   r#   z-SigningCertificateV2Provider.build_attr_valueI   s     ():):;;s   Nr(   )r)   r*   r+   r,   r   r-   r.   r   Certificater7   r
   SigningCertificateV2r#   r0   r1   r"   r   r   <   s7     3NC2)T%5%5 )<s7O7O <r1   r   c                   N    e Zd ZU dZdZeed<   defdZd	de	j                  fdZy)
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                     || _         y r6   )r=   )r    r=   s     r"   r7   zSigningTimeProvider.__init__X   s	    "r1   r$   c                 r   K   t        j                  dt        j                  | j                        i      S w)Nutc_time)r   Timer   UTCTimer=   r   s     r"   r#   z$SigningTimeProvider.build_attr_value[   s'     xxT\\$..%ABCCs   57Nr(   )r)   r*   r+   r,   r   r-   r.   r   r7   r   rA   r#   r0   r1   r"   r   r   M   s1     )NC(#( #Dsxx Dr1   r   c                   j    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y)
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                     || _         y r6   r&   )r    r&   s     r"   r7   zAdobeRevinfoProvider.__init__p   s	    
r1   r$   c                 "   K   | j                   S wr6   rF   r   s     r"   r#   z%AdobeRevinfoProvider.build_attr_values   s      zzs   Nr(   )r)   r*   r+   r,   r   r-   r.   asn1_pdfRevocationInfoArchivalr7   r   r#   r0   r1   r"   r   r   e   sB     ;NC:h==  	(11	2r1   r   c                   d    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y)
r   cms_algorithm_protectionr   digest_algosignature_algoc                      || _         || _        y r6   )rL   rM   )r    rL   rM   s      r"   r7   z'CMSAlgorithmProtectionProvider.__init__|   s     ',r1   r$   c                   K   d| j                   i}| j                   dk(  r6| j                  }|d   j                  dk(  rdt        j                  d      d}t        j                  t        j                  |      | j                  d      S w)N	algorithmshake256ed448shake256_leni   )rP   
parameters)digest_algorithmsignature_algorithm)	rL   rM   nativer   Integerr   CMSAlgorithmProtectionr   DigestAlgorithm)r    r!   digest_algorithm_argsmechs       r"   r#   z/CMSAlgorithmProtectionProvider.build_attr_value   s      "-d.>.> ?z)&&DK ''72!/"&,,s"3)% ))$)$9$9)% (,':':	
 	
s   B	BNr(   )r)   r*   r+   r   r-   r.   r   SignedDigestAlgorithmr7   r   rY   r#   r0   r1   r"   r   r   y   s?    4NC4--050K0K- 
		#	#
r1   r   c            	       L    e Zd Z	 	 d	dedededefdZd
dej                  fdZ	y)r   rU   
data_to_tstimestamper	attr_typec                 J    || _         || _        || _        || _        || _        y r6   )r   rU   r`   data	prehashed)r    rU   r_   r`   ra   rd   s         r"   r7   zTSTProvider.__init__   s*     ( 0&	"r1   r$   c                 v  K   | j                   }| j                  r| j                  }nKt        |      }t	        j
                  |      }|j                  | j                         |j                         }|r| j                  j                  |      }n| j                  j                  ||      }| d {   S 7 wr6   )rU   rd   rc   r   r   Hashupdatefinalizer`   async_dummy_responseasync_timestamp)r    r!   rU   digestmd_specmdts_coros          r"   r#   zTSTProvider.build_attr_value   s     00>>YYF01ABGW%BIIdii [[]F&&;;<LMG&&66v?OPG}}s   B0B92B73B9N)signature_time_stamp_tokenFr(   )
r)   r*   r+   r-   bytesr   r7   r   ContentInfor#   r0   r1   r"   r   r      sE     6## # !	#
 #s r1   r   c                   *    e Zd ZdZdededee   fdZy)r   z
    .. versionadded:: 0.14.0

    Interface for setting up signed attributes, independently of the
    :class:`~pyhanko.sign.signers.pdf_cms.Signer` hierarchy.
    data_digestrU   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    rs   rU   s      r"   signed_attr_providersz1SignedAttributeProviderSpec.signed_attr_providers   s
     "!r1   N)	r)   r*   r+   r,   rp   r-   r   r   ru   r0   r1   r"   r   r      s*    " "47"	&	'"r1   r   c            	       B    e Zd ZdZdedej                  dedee	   fdZ
y)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_attrsrU   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    rw   rx   rU   s       r"   unsigned_attr_providersz5UnsignedAttributeProviderSpec.unsigned_attr_providers   s
      "!r1   N)r)   r*   r+   r,   rp   r   CMSAttributesr-   r   r   rz   r0   r1   r"   r   r      s>    "" ''" 	"
 
&	'"r1   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   r0   r1   r"   <module>r      s    
  % ' ' &   1 
 $	 ><#7 <"D. D0/ (
%9 
>& >"#'' ","CGG "r1   