
    5i                     j    S SK 7  S SKJrJrJrJr  S SKJrJrJ	r	  SS/r
SSS\" 5       S4S jrS	S jrg)
    )*)DerNullDerSequenceDerObjectIdDerOctetString)PBES1PBES2	PbesErrorwrapunwrapNc                 ,   Uc  [        [        U5      /5      nO[        [        U5      U/5      n[        SU[        U 5      /5      nUR                  5       n	Uc  U	$ U(       d  [	        S5      e[        U5      nUc  Sn[        R                  " XX4U5      $ )a  Wrap a private key into a PKCS#8 blob (clear or encrypted).

Args:

  private_key (bytes):
    The private key encoded in binary form. The actual encoding is
    algorithm specific. In most cases, it is DER.

  key_oid (string):
    The object identifier (OID) of the private key to wrap.
    It is a dotted string, like ``'1.2.840.113549.1.1.1'`` (for RSA keys)
    or ``'1.2.840.10045.2.1'`` (for ECC keys).

Keyword Args:

  passphrase (bytes or string):
    The secret passphrase from which the wrapping key is derived.
    Set it only if encryption is required.

  protection (string):
    The identifier of the algorithm to use for securely wrapping the key.
    Refer to :ref:`the encryption parameters<enc_params>` .
    The default value is ``'PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC'``.

  prot_params (dictionary):
    Parameters for the key derivation function (KDF).
    Refer to :ref:`the encryption parameters<enc_params>` .

  key_params (DER object or None):
    The ``parameters`` field to use in the ``AlgorithmIdentifier``
    SEQUENCE. If ``None``, no ``parameters`` field will be added.
    By default, the ASN.1 type ``NULL`` is used.

  randfunc (callable):
    Random number generation function; it should accept a single integer
    N and return a string of random data, N bytes long.
    If not specified, a new RNG will be instantiated
    from :mod:`Crypto.Random`.

Returns:
  bytes: The PKCS#8-wrapped private key (possibly encrypted).
r   zEmpty passphrasez"PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC)r   r   r   encode
ValueErrortobytesr	   encrypt)
private_keykey_oid
passphrase
protectionprot_params
key_paramsrandfunc	algorithmpk_infopk_info_ders
             ]/var/www/html/BTCUSD/btcusdt_trading_app/venv/lib/python3.13/site-packages/Crypto/IO/PKCS8.pyr   r   2   s    j W!5 67	W!5z BC	{+ G
 .."K+,, $J9
==#(< <    c                    Ub[  [        U5      nSn [        R                  " X5      n SnU(       d   [        R                  " X5      n SnU(       d  [        SW-  5      e[        5       R                  U S	S
9n[        U5      S:X  a  U(       d  [        S5      eUS   S:X  a  [        U5      S;  a  [        S5      eO/US   S:X  a  [        U5      S;  a  [        S5      eO[        S5      e[        5       R                  US   SS
9n[        5       R                  US   5      R                  n[        U5      S:X  a  SnO [        5       R                  US   5        Sn[        5       R                  US   5      R                  n	XyU4$ ! [         a  nS[	        U5      -  n SnAGN{SnAf[
         a    Sn GNf = f! [         a  nWS[	        U5      -  -  n SnAGNSnAf[
         a	    WS-  n GNf = f!   US   n N= f)a  Unwrap a private key from a PKCS#8 blob (clear or encrypted).

Args:
  p8_private_key (bytes):
    The private key wrapped into a PKCS#8 container, DER encoded.

Keyword Args:
  passphrase (byte string or string):
    The passphrase to use to decrypt the blob (if it is encrypted).

Return:
  A tuple containing

   #. the algorithm identifier of the wrapped key (OID, dotted string)
   #. the private key (bytes, DER encoded)
   #. the associated parameters (bytes, DER encoded) or ``None``

Raises:
  ValueError : if decoding fails
NFTz	PBES1[%s]zPBES1[Invalid]z
,PBES2[%s]z,PBES2[Invalid]zError decoding PKCS#8 (%s))            )nr_elementsr   z;Not a valid clear PKCS#8 structure (maybe it is encrypted?)r   )r    r!   z#Not a valid PrivateKeyInfo SEQUENCE   )r    r!   r"   )r$   r   )r   r   decryptr
   strr   r	   r   decodelenr   valuer   r   payload)
p8_private_keyr   founde	error_strr   algoalgo_oidalgo_paramsr   s
             r   r   r      s   , Z(
	)"]]>FNE /!&~!J 9IEFFm"">|"LG
7|q 4 5 	50 qzQw<v%BCC &	qw<y(BCC ) >??=
?D}##DG,22H
4yA~	"IT!W%K
 !"))'!*5==K ;//I  	-#c!f,I 	)(I	)  3\CF22	 /..	/b	"q'KsF   F F; ?G5 
F8F%%F87F8;
G2GG21G25G>)N)Crypto.Util.py3compatCrypto.Util.asn1r   r   r   r   Crypto.IO._PBESr   r	   r
   __all__r   r    r   r   <module>r7      sF   F $  4 3 8
 +/4gi$L<^a0r   