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    