o
    6h`
                     @   s   d Z ddlmZmZ ddlmZmZ dZG dd dejZ	G dd dejZ
G d	d
 d
ejZdd Zdd Zdd Zdd ZdS )zuASN1 encoding helpers for converting between PKCS1 and PKCS8.

Required by rsa_backend but not cryptography_backend.
    )decoderencoder)	namedtypeunivz1.2.840.113549.1.1.1c                   @   s4   e Zd ZdZeede ede	 Z
dS )RsaAlgorithmIdentifierzAASN1 structure for recording RSA PrivateKeyAlgorithm identifiers.rsaEncryption
parametersN)__name__
__module____qualname____doc__r   
NamedTypes	NamedTyper   ObjectIdentifierNullcomponentType r   r   g/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/jose/backends/_asn1.pyr      s
    r   c                	   @   s@   e Zd ZdZeede ede	 ede
 ZdS )PKCS8PrivateKeyz0ASN1 structure for recording PKCS8 private keys.versionprivateKeyAlgorithm
privateKeyN)r	   r
   r   r   r   r   r   r   Integerr   OctetStringr   r   r   r   r   r      s    r   c                   @   s2   e Zd ZdZeede ede	 Z
dS )PublicKeyInfoz/ASN1 structure for recording PKCS8 public keys.	algorithm	publicKeyN)r	   r
   r   r   r   r   r   r   r   	BitStringr   r   r   r   r   r      s
    r   c                 C   s:   t j| t d}z	|d }W |d S  ty   tdw )1Convert a PKCS8-encoded RSA private key to PKCS1.asn1Specr   zInvalid private key encodingr   )r   decoder   
IndexError
ValueError	pkcs8_keydecoded_valuesdecoded_keyr   r   r   rsa_private_key_pkcs8_to_pkcs1&   s   
r(   c                 C   s6   t  }t|d< t }d|d< ||d< | |d< t|S )1Convert a PKCS1-encoded RSA private key to PKCS8.r   r   r   r   r   )r   RSA_ENCRYPTION_ASN1_OIDr   r   encode	pkcs1_keyr   r%   r   r   r   rsa_private_key_pkcs1_to_pkcs82   s   
r.   c                 C   s6   t  }t|d< t }||d< tj| |d< t|S )r)   r   r   r   )r   r*   r   r   r   fromOctetStringr   r+   r,   r   r   r   rsa_public_key_pkcs1_to_pkcs8?   s   
r0   c                 C   s@   t j| t d}z|d }W n ty   tdw |d  S )r   r   r   zInvalid public key encoding.r   )r   r!   r   r"   r#   asOctetsr$   r   r   r   rsa_public_key_pkcs8_to_pkcs1K   s   r2   N)r   pyasn1.codec.derr   r   pyasn1.typer   r   r*   Sequencer   r   r   r(   r.   r0   r2   r   r   r   r   <module>   s    
