o
    Þý°j|	  ã                   @   s\   d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	 G dd„ deƒZ
G dd„ deƒZd	S )
é    )ÚAnyÚType)Úserialization)ÚGenericPrivateKeyÚGenericPublicKey)ÚAlgorithmKeyMismatchc                   @   s\   e Zd ZU dZeed< dZeed< deddfdd„Zede	ddfd	d
„ƒZ
de	fdd„ZdS )ÚCryptographyPublicKeyNÚkeyÚkey_clsÚreturnc                 C   ó,   | j d u r	tdƒ‚t|| j ƒst‚|| _d S ©NzUndefined private key class©r
   Ú	TypeErrorÚ
isinstancer   r	   ©Úselfr	   © r   úŽ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/dns/dnssecalgs/cryptography.pyÚ__init__   ó   
ÿ
zCryptographyPublicKey.__init__Ú
public_pemr   c                 C   s   t  |¡}| |d�S ©N©r	   )r   Úload_pem_public_key)Úclsr   r	   r   r   r   Úfrom_pem   s   

zCryptographyPublicKey.from_pemc                 C   s   | j jtjjtjjd�S )N)ÚencodingÚformat)r	   Úpublic_bytesr   ÚEncodingÚPEMÚPublicFormatÚSubjectPublicKeyInfo©r   r   r   r   Úto_pem   s   þzCryptographyPublicKey.to_pem)Ú__name__Ú
__module__Ú__qualname__r	   r   Ú__annotations__r
   r   ÚclassmethodÚbytesr   r%   r   r   r   r   r   	   s   
 	r   c                   @   sˆ   e Zd ZU dZeed< dZeed< ee ed< deddfdd„Z	dd	d
„Z
e	ddededB ddfdd„ƒZddedB defdd„ZdS )ÚCryptographyPrivateKeyNr	   r
   Ú
public_clsr   c                 C   r   r   r   r   r   r   r   r   '   r   zCryptographyPrivateKey.__init__r   c                 C   s   | j | j ¡ d�S r   )r-   r	   Ú
public_keyr$   r   r   r   r.   0   s   z!CryptographyPrivateKey.public_keyÚprivate_pemÚpasswordr   c                 C   s   t j||d�}| |d�S )N)r0   r   )r   Úload_pem_private_key)r   r/   r0   r	   r   r   r   r   3   s   
zCryptographyPrivateKey.from_pemc                 C   s2   |rt  |¡}nt  ¡ }| jjt jjt jj|d�S )N)r   r   Úencryption_algorithm)	r   ÚBestAvailableEncryptionÚNoEncryptionr	   Úprivate_bytesr    r!   ÚPrivateFormatÚPKCS8)r   r0   r2   r   r   r   r%   :   s   ýzCryptographyPrivateKey.to_pem)r   r   )N)r&   r'   r(   r	   r   r)   r
   r   r   r   r.   r*   r+   r   r%   r   r   r   r   r,   "   s    
 
	ÿÿÿþr,   N)Útypingr   r   Úcryptography.hazmat.primitivesr   Údns.dnssecalgs.baser   r   Údns.exceptionr   r   r,   r   r   r   r   Ú<module>   s    