o
    �õ±j>	  ã                   @   s&   d dl Z d dlmZ G dd„ dƒZdS )é    N)ÚRSAPrivateKeyBlobc                   @   s\   e Zd Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZed	d
„ ƒZdd„ Z	dd„ Z
dd„ ZdS )ÚPVKFilec                 C   s4   d| _ d| _d | _d | _d | _d | _d | _d | _d S )Nì   qka r   )ÚmagicÚreservedÚkeytypeÚisencryptedÚ
saltlengthÚ	keylengthÚsaltblobÚkeyblob©Úself© r   ú‹/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/winacl/dtyp/wcee/pvkfile.pyÚ__init__   s   
zPVKFile.__init__c                 C   sD   t | tƒr	|  ¡ } tƒ }| |_d|_d|_t|ƒ|_d|_	||_
|S )Nr   ó    )Ú
isinstanceÚstrÚencoder   r   r   r	   Úlenr
   r   r   )r   ÚkeydataÚpvkr   r   r   Úconstruct_unencrypted   s   

zPVKFile.construct_unencryptedc                 C   s8   t | dƒ�}t |¡W  d   ƒ S 1 sw   Y  d S )NÚrb)Úopenr   Úfrom_buffer)ÚfilepathÚfr   r   r   Ú	from_file   s   $ÿzPVKFile.from_filec                 C   s   t  t | ¡¡S )N)r   r   ÚioÚBytesIO)Údatar   r   r   Ú
from_bytes$   s   zPVKFile.from_bytesc                 C   s¸   t ƒ }tj|  d¡ddd�|_d|jksJ ‚tj|  d¡ddd�|_|  d¡|_tj|  d¡ddd�|_tj|  d¡ddd�|_tj|  d¡ddd�|_	|  |j¡|_
|  |j	¡|_|S )Né   ÚlittleF©Ú	byteorderÚsignedr   )r   Úintr#   Úreadr   r   r   r   r	   r
   r   r   )Úbuffr   r   r   r   r   (   s   zPVKFile.from_bufferc                 C   s¼   d}|| j jdddd�7 }|| jjdddd�7 }|| j7 }|| jjdddd�7 }| jd u r0d| _| jd u r8d| _|t| jƒjdddd�7 }|t| jƒjdddd�7 }|| j7 }|| j7 }|S )Nr   r$   r%   Fr&   )r   Úto_bytesr   r   r   r   r   r   )r   r"   r   r   r   r,   6   s   




zPVKFile.to_bytesc                 C   s(   | j dd …  d¡rt | j ¡ ¡ S d S )Né   s   RSA2)r   Ú
startswithr   r#   Úget_keyr   r   r   r   r/   F   s   ÿzPVKFile.get_keyc                 C   s*   d}| j D ]}|d|| j | f 7 }q|S )NÚ z%s: %s
)Ú__dict__)r   ÚtÚkr   r   r   Ú__str__J   s   
zPVKFile.__str__N)Ú__name__Ú
__module__Ú__qualname__r   Ústaticmethodr   r   r#   r   r,   r/   r4   r   r   r   r   r      s    




r   )r    Úwinacl.dtyp.wcee.rsaprivkeyr   r   r   r   r   r   Ú<module>   s    