o
    5׾gK'                     @   s(  U 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
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 d d	lmZ d d
lmZ d dlmZmZmZ eG dd dZeddG dd dZd ZZ eedZ!ee"ee f e#d< defddZ$de%de%fddZ&de%de%fddZ'dS )    )	dataclass)	timedelta)DictListOptionalTypeUnionN)ValidationContext)ConfigurationError)	LogConfigparse_logging_config)DEFAULT_TIME_TOLERANCEparse_trust_config)DEFAULT_SIGNING_STAMP_STYLE)KeyUsageConstraints)BaseStampStyleQRStampStyleTextStampStylec                   @   s   e Zd ZU dZeeef ed< 	 eeef ed< 	 eed< 	 eed< 	 eed< 	 e	ed< 	 eed< 	 dd
dZ
	ddee de	fddZ		ddee defddZ		ddee deeef fddZd	S )	CLIConfigz%
    CLI configuration settings.
    validation_contextsstamp_stylesdefault_validation_contextdefault_stamp_styletime_toleranceretroactive_revinfo
raw_configNc                 C   s6   |p| j }z| j| W S  ty   td| dw )Nz&There is no validation context named ''.)r   r   KeyErrorr
   )selfname r    \/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/pyhanko/cli/config.py_get_validation_settings_raw\   s   

z&CLIConfig._get_validation_settings_rawFr   as_dictc                 C   s0   |  |}t|| j| j}|r|S tdi |S )a  
        Retrieve a validation context by name.

        :param name:
            The name of the validation context. If not supplied, the value
            of :attr:`default_validation_context` will be used.
        :param as_dict:
            If ``True`` return the settings as a keyword argument dictionary.
            If ``False`` (the default), return a
            :class:`~pyhanko_certvalidator.context.ValidationContext`
            object.
        Nr    )r"   r   r   r   r	   )r   r   r#   	vc_config	vc_kwargsr    r    r!   get_validation_contexte   s
   

z CLIConfig.get_validation_contextreturnc                 C   s   |  |}zt|d }W n ty   i }Y nw z|d }|d| W n	 ty.   Y nw z|d }|d| W n	 tyD   Y nw t|S )a:  
        Get a set of key usage constraints for a given validation context.

        :param name:
            The name of the validation context. If not supplied, the value
            of :attr:`default_validation_context` will be used.
        :return:
            A :class:`.KeyUsageConstraints` object.
        zsigner-key-usage-policyzsigner-key-usagez	key-usagezsigner-extd-key-usagezextd-key-usage)r"   dictr   
setdefaultr   from_config)r   r   r$   policy_settingskey_usage_stringsr    r    r!   get_signer_key_usagesz   s&   

zCLIConfig.get_signer_key_usagesc              
   C   s   |p| j }| j|d}|du rtd| dzt|}W n ttfy5 } z	td| d|d}~ww t|dd }|	|S )a  
        Retrieve a stamp style by name.

        :param name:
            The name of the style. If not supplied, the value
            of :attr:`default_stamp_style` will be used.
        :return:
            A :class:`TextStampStyle` or `QRStampStyle` object.
        NzThere is no stamp style named 'r   z%Could not process stamp style named ''typetext)
r   r   getr
   r(   	TypeError
ValueErrorSTAMP_STYLE_TYPESpopr*   )r   r   configstyle_configeclsr    r    r!   get_stamp_style   s    


zCLIConfig.get_stamp_style)N)NF)__name__
__module____qualname____doc__r   strr(   __annotations__r   boolr"   r   r&   r   r-   r   r   r   r:   r    r    r    r!   r      sF   
 



&
r   T)frozenc                   @   s>   e Zd ZU dZeed< 	 eee e	f ed< 	 e
e ed< dS )CLIRootConfigzs
    Config settings that are only relevant tothe CLI root and are not exposed
    to subcommands and plugins.
    r6   
log_configplugin_endpointsN)r;   r<   r=   r>   r   r@   r   r   r?   r   r   r    r    r    r!   rC      s   
 rC   default)qrr0   r4   r'   c              	   C   s>   t | pi }tdi t|dtdi t|d|iiS )Nr6   r   r    )yaml	safe_loadrC   process_root_config_settingsr   process_config_dict)yaml_strconfig_dictr    r    r!   parse_cli_config   s   rN   rM   c                 C   s,   |  dg }|  di }t|}t||dS )Npluginslogging)rD   rE   )r1   r   r(   )rM   rO   log_config_specrD   r    r    r!   rJ      s   rJ   c           
      C   s   t i i}z| d }|| W n	 ty   Y nw ttjddi}z| d }|| W n	 ty5   Y nw | dt }| dt}| dtj}t	|t
sRtdt|d	}t| d
d}	t||||	||dS )Nzvalidation-contexts	__stamp__)z
stamp-text
backgroundzstamp-styleszdefault-validation-contextzdefault-stamp-styleztime-tolerancez5time-tolerance parameter must be specified in seconds)secondszretroactive-revinfoF)r   r   r   r   r   r   )DEFAULT_VALIDATION_CONTEXTupdater   DEFAULT_STAMP_STYLEr   
stamp_textr1   r   rT   
isinstanceintr
   r   rA   r(   )
rM   vcsvc_specsstamp_configsstamp_specs
default_vcr   time_tolerance_secondsr   r   r    r    r!   rK     sR   

rK   )(dataclassesr   datetimer   typingr   r   r   r   r   rH   pyhanko_certvalidatorr	   pyhanko.config.errorsr
   pyhanko.config.loggingr   r   pyhanko.config.trustr   r   pyhanko.sign.signersr    pyhanko.sign.validation.settingsr   pyhanko.stampr   r   r   r   rC   rU   rW   r4   r?   r@   rN   r(   rJ   rK   r    r    r    r!   <module>   s.     ),
