U
    g                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 ddl
mZmZ dd	lmZmZmZmZmZ d
ddgZe jG dd
 d
e jZeddG dd dZeddG dd dZG dd deZG dd deZG dd deZdS )    N)	dataclass)IterableOptional)cms)TimeStamper   )CMSAttributeProviderTSTProvider   )CertifiedAttributeChoicesCommitmentTypeIdentifierCommitmentTypeIndicationSignaturePolicyIdentifierSignerAttributesV2GenericCommitmentCAdESSignedAttrSpecSignerAttrSpecc                   @   sN   e Zd Ze Ze Ze Ze Ze Z	e Z
eedddZdS )r   returnc                 C   s   t dt| j iS )NZcommitment_type_id)r   r   namelower)self r   9/tmp/pip-unpacked-wheel-owvgwkas/pyhanko/sign/ades/api.pyasn1!   s    zGenericCommitment.asn1N)__name__
__module____qualname__enumautoZPROOF_OF_ORIGINZPROOF_OF_RECEIPTZPROOF_OF_DELIVERYZPROOF_OF_SENDERZPROOF_OF_APPROVALZPROOF_OF_CREATIONpropertyr   r   r   r   r   r   r      s   T)frozenc                   @   s.   e Zd ZU dZeej ed< eej ed< dS )r   aO  
    Class that controls the ``signer-attributes-v2`` signed CAdES attribute.

    These represent attributes of the signing entity, not the signature or
    signed content.

    .. note::
        Out of the box, only basic claimed attributes and certified attributes
        through V2 X.509 attribute certificates are supported.
    claimed_attrscertified_attrsN)	r   r   r   __doc__r   r   ZAttCertAttribute__annotations__ZAttributeCertificateV2r   r   r   r   r   (   s   
c                   @   sb   e Zd ZU dZdZee ed< dZe	ed< dZ
ee ed< dZee ed< dee dd	d
ZdS )r   zI
    Class that controls signed CAdES attributes on a PDF signature.
    Ncommitment_typeFtimestamp_contentsignature_policy_identifiersigner_attributes)timestamperc                 c   sh   | j r"|d k	r"t|||dddV  | jd k	r8t| jV  | jd k	rNt| jV  | jd k	rdt| jV  d S )NZcontent_time_stampT)Zdigest_algorithmZ
data_to_tsr*   Z	attr_typeZ	prehashed)r'   r	   r(   SigPolicyIDProviderr&   CommitmentTypeProviderr)   SignerAttributesProvider)r   Zmessage_digestZmd_algorithmr*   r   r   r   prepare_providersi   s    


z%CAdESSignedAttrSpec.prepare_providers)N)r   r   r   r$   r&   r   r   r%   r'   boolr(   r   r)   r   r   r.   r   r   r   r   r   @   s   

 c                   @   s.   e Zd ZdZedddZd
edddZd	S )r,   r&   r&   c                 C   s
   || _ d S Nr0   )r   r&   r   r   r   __init__   s    zCommitmentTypeProvider.__init__Fr   c                    s   | j S r1   r0   r   dry_runr   r   r   build_attr_value   s    z'CommitmentTypeProvider.build_attr_valueN)F)r   r   r   attribute_typer   r2   r5   r   r   r   r   r,      s   r,   c                   @   s.   e Zd ZdZedddZd
edddZd	S )r+   r(   	policy_idc                 C   s
   || _ d S r1   r7   )r   r8   r   r   r   r2      s    zSigPolicyIDProvider.__init__Fr   c                    s   | j S r1   r7   r3   r   r   r   r5      s    z$SigPolicyIDProvider.build_attr_valueN)F)r   r   r   r6   r   r2   r5   r   r   r   r   r+      s    r+   c                   @   s.   e Zd ZdZedddZd
edddZd	S )r-   Zsigner_attributes_v2signer_attr_specc                 C   s
   || _ d S r1   r9   )r   r:   r   r   r   r2      s    z!SignerAttributesProvider.__init__Fr   c                    sH   | j }t|j}t|j}i }|r*||d< |r@dd |D |d< t|S )NZclaimed_attributesc                 S   s   g | ]}t d |dqS )	attr_cert)r   value)r   ).0r;   r   r   r   
<listcomp>   s   z=SignerAttributesProvider.build_attr_value.<locals>.<listcomp>Zcertified_attributes_v2)r:   listr"   r#   r   )r   r4   specZclaimedZ	certifiedresultr   r   r   r5      s    


z)SignerAttributesProvider.build_attr_valueN)F)r   r   r   r6   r   r2   r   r5   r   r   r   r   r-      s   r-   )r   Zdataclassesr   typingr   r   Z
asn1cryptor   Zpyhanko.sign.timestampsr   
attributesr   r	   Z
cades_asn1r   r   r   r   r   __all__uniqueEnumr   r   r   r,   r+   r-   r   r   r   r   <module>   s    
>
