o
    bi                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ	 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mZ g d
Zejejejejejejf Ze	jZG dd dZe	j Z e	j!Z!ejej"ef Z#dddZ$d ddZ%dS )!    )annotationsN)Iterable)x509)pkcs12)serialization)PBES)dsaeced448ed25519rsa)PrivateKeyTypes)r   PKCS12CertificatePKCS12KeyAndCertificatesPKCS12PrivateKeyTypesload_key_and_certificatesload_pkcs12serialize_java_truststoreserialize_key_and_certificatesc                   @  s^   e Zd ZdddZedd
dZedddZedddZd ddZd!ddZ	d"ddZ
dS )#r   keyPrivateKeyTypes | NonecertPKCS12Certificate | Noneadditional_certslist[PKCS12Certificate]c                 C  sx   |d urt |tjtjtjtjt	j
fstd|d ur$t |ts$tdtdd |D s1td|| _|| _|| _d S )NLKey must be RSA, DSA, EllipticCurve, ED25519, or ED448 private key, or None.z/cert must be a PKCS12Certificate object or Nonec                 s  s    | ]}t |tV  qd S N)
isinstancer   ).0Zadd_cert r   m/home/kim/smarthome/.venv/lib/python3.10/site-packages/cryptography/hazmat/primitives/serialization/pkcs12.py	<genexpr>E   s
    
z4PKCS12KeyAndCertificates.__init__.<locals>.<genexpr>z@all values in additional_certs must be PKCS12Certificate objects)r   r   RSAPrivateKeyr   DSAPrivateKeyr	   EllipticCurvePrivateKeyr   Ed25519PrivateKeyr
   Ed448PrivateKey	TypeErrorr   all_key_cert_additional_certs)selfr   r   r   r   r   r    __init__/   s.   


z!PKCS12KeyAndCertificates.__init__returnc                 C     | j S r   )r)   r,   r   r   r    r   Q      zPKCS12KeyAndCertificates.keyc                 C  r/   r   )r*   r0   r   r   r    r   U   r1   zPKCS12KeyAndCertificates.certc                 C  r/   r   )r+   r0   r   r   r    r   Y   r1   z)PKCS12KeyAndCertificates.additional_certsotherobjectboolc                 C  s2   t |tstS | j|jko| j|jko| j|jkS r   )r   r   NotImplementedr   r   r   )r,   r2   r   r   r    __eq__]   s   


zPKCS12KeyAndCertificates.__eq__intc                 C  s   t | j| jt| jfS r   )hashr   r   tupler   r0   r   r   r    __hash__g   s   z!PKCS12KeyAndCertificates.__hash__strc                 C  s   d}| | j| j| jS )Nz@<PKCS12KeyAndCertificates(key={}, cert={}, additional_certs={})>)formatr   r   r   )r,   fmtr   r   r    __repr__j   s   z!PKCS12KeyAndCertificates.__repr__N)r   r   r   r   r   r   )r.   r   )r.   r   )r.   r   )r2   r3   r.   r4   )r.   r7   )r.   r;   )__name__
__module____qualname__r-   propertyr   r   r   r6   r:   r>   r   r   r   r    r   .   s    
"


r   certsIterable[PKCS12Certificate]encryption_algorithm(serialization.KeySerializationEncryptionr.   bytesc                 C  s,   | st dt|tjstdt| |S )Nz!You must supply at least one certFKey encryption algorithm must be a KeySerializationEncryption instance)
ValueErrorr   r   KeySerializationEncryptionr'   rust_pkcs12r   )rC   rE   r   r   r    r   {   s   r   namebytes | Noner   PKCS12PrivateKeyTypes | Noner   x509.Certificate | NonecasIterable[_PKCS12CATypes] | Nonec                 C  sp   |d urt |tjtjtjtjt	j
fstdt |tjs!td|d u r/|d u r/|s/tdt| ||||S )Nr   rH   z1You must supply at least one of key, cert, or cas)r   r   r"   r   r#   r	   r$   r   r%   r
   r&   r'   r   rJ   rI   rK   r   )rL   r   r   rP   rE   r   r   r    r      s.   


r   )rC   rD   rE   rF   r.   rG   )rL   rM   r   rN   r   rO   rP   rQ   rE   rF   r.   rG   )&
__future__r   typingcollections.abcr   Zcryptographyr   Z"cryptography.hazmat.bindings._rustr   rK   Zcryptography.hazmat.primitivesr   Z-cryptography.hazmat.primitives._serializationr   Z)cryptography.hazmat.primitives.asymmetricr   r	   r
   r   r   Z/cryptography.hazmat.primitives.asymmetric.typesr   __all__Unionr"   r#   r$   r%   r&   r   r   r   r   r   CertificateZ_PKCS12CATypesr   r   r   r   r   r    <module>   s:   	C
