
    ,huy                         g d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZmZmZ  G d
 de      ZddZddZd Zd Zd Zd Zd Z d Z!d Z"ddZ#e#Z$dZ%y))generate	construct
import_keyRsaKeyoid    N)Random)tobytesbordtostr)DerSequenceDerNull)bytes_to_long)Integer)test_probable_primegenerate_probable_prime	COMPOSITE)_expand_subject_public_key_info_create_subject_public_key_info _extract_subject_public_key_infoc                   L   e Zd ZdZd Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z	 	 d&dZd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'y)'r   a  Class defining an RSA key, private or public.
    Do not instantiate directly.
    Use :func:`generate`, :func:`construct` or :func:`import_key` instead.

    :ivar n: RSA modulus
    :vartype n: integer

    :ivar e: RSA public exponent
    :vartype e: integer

    :ivar d: RSA private exponent
    :vartype d: integer

    :ivar p: First factor of the RSA modulus
    :vartype p: integer

    :ivar q: Second factor of the RSA modulus
    :vartype q: integer

    :ivar invp: Chinese remainder component (:math:`p^{-1} \text{mod } q`)
    :vartype invp: integer

    :ivar invq: Chinese remainder component (:math:`q^{-1} \text{mod } p`)
    :vartype invq: integer

    :ivar u: Same as ``invp``
    :vartype u: integer
    c                 x   t        |j                               }t        d      }|t        d      z  }|||fvrt        d      |j                         D ]  \  }}t	        | d|z   |        ||k(  rJ| j
                  | j                  dz
  z  | _        | j
                  | j                  dz
  z  | _	        d| _
        yy)a.  Build an RSA key.

        :Keywords:
          n : integer
            The modulus.
          e : integer
            The public exponent.
          d : integer
            The private exponent. Only required for private keys.
          p : integer
            The first factor of the modulus. Only required for private keys.
          q : integer
            The second factor of the modulus. Only required for private keys.
          u : integer
            The CRT coefficient (inverse of p modulo q). Only required for
            private keys.
        ne)pqduzSome RSA components are missing_   N)setkeys
ValueErroritemssetattr_d_p_dp_q_dq_invq)selfkwargs	input_set
public_setprivate_set	componentvalues          V/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/PublicKey/RSA.py__init__zRsaKey.__init__R   s    & &	_
 3';#<<[*55>?? & 	2IuD#	/51	2#ww$''A+.DHww$''A+.DHDJ $    c                 ,    t        | j                        S N)int_nr,   s    r3   r   zRsaKey.nq       477|r5   c                 ,    t        | j                        S r7   )r8   _er:   s    r3   r   zRsaKey.eu   r;   r5   c                 b    | j                         st        d      t        | j                        S )Nz-No private exponent available for public keys)has_privateAttributeErrorr8   r&   r:   s    r3   r   zRsaKey.dy   s(    ! !PQQ477|r5   c                 b    | j                         st        d      t        | j                        S )Nz.No CRT component 'p' available for public keys)r?   r@   r8   r'   r:   s    r3   r   zRsaKey.p   (    ! !QRR477|r5   c                 b    | j                         st        d      t        | j                        S )Nz.No CRT component 'q' available for public keys)r?   r@   r8   r)   r:   s    r3   r   zRsaKey.q   rB   r5   c                 b    | j                         st        d      t        | j                        S )Nz/No CRT component 'dp' available for public keys)r?   r@   r8   r(   r:   s    r3   dpz	RsaKey.dp   (    ! !RSS488}r5   c                 b    | j                         st        d      t        | j                        S )Nz/No CRT component 'dq' available for public keys)r?   r@   r8   r*   r:   s    r3   dqz	RsaKey.dq   rF   r5   c                     | j                         st        d      | j                  *| j                  j	                  | j
                        | _        t        | j                        S )Nz1No CRT component 'invq' available for public keys)r?   r@   r+   r)   inverser'   r8   r:   s    r3   invqzRsaKey.invq   sJ    ! !TUU::1DJ4::r5   c                     | j                   S r7   )r   r:   s    r3   invpzRsaKey.invp   s    vvr5   c                 b    | j                         st        d      t        | j                        S )Nz.No CRT component 'u' available for public keys)r?   r@   r8   _ur:   s    r3   r   zRsaKey.u   rB   r5   c                 6    | j                   j                         S )zSize of the RSA modulus in bitsr9   size_in_bitsr:   s    r3   rR   zRsaKey.size_in_bits   s    ww##%%r5   c                 H    | j                   j                         dz
  dz  dz   S )z9The minimal amount of bytes that can hold the RSA modulusr       rQ   r:   s    r3   size_in_byteszRsaKey.size_in_bytes   s$    $$&*q0144r5   c                     d|cxk  r| j                   k  st        d       t        d      t        t        t	        |      | j
                  | j                               S )Nr   zPlaintext too large)r9   r#   r8   powr   r=   )r,   	plaintexts     r3   _encryptzRsaKey._encrypt   sQ    I''233 (2333wy)477DGG<==r5   c                    d|cxk  r| j                   k  st        d       t        d      | j                         st        d      t	        j
                  d| j                         }t	        |      t        || j                  | j                         z  | j                   z  }t        || j                  | j                        }t        || j                  | j                        }||z
  | j                  z  | j                  z  }|| j                  z  |z   }t	        j                  |j                  | j                         || j                         }|S )Nr   zCiphertext too largezThis is not a private keyr    )min_inclusivemax_exclusive)r9   r#   r?   	TypeErrorr   random_rangerW   r=   r(   r'   r*   r)   rO   _mult_modulo_bytesrJ   )	r,   
ciphertextrcpm1m2hmpresults	            r3   _decrypt_to_byteszRsaKey._decrypt_to_bytes   s   J((344 )344!788
   qHZ 3q$''477#;;dggETXXtww'TXXtww'2g DGG+[2 ++IIdgg&GG r5   c                 6    t        | j                  |            S )zLegacy private method)r   rh   r,   r`   s     r3   _decryptzRsaKey._decrypt   s     T33J?@@r5   c                     t        | d      S )z"Whether this is an RSA private keyr&   )hasattrr:   s    r3   r?   zRsaKey.has_private   s     tT""r5   c                      yNT r:   s    r3   can_encryptzRsaKey.can_encrypt       r5   c                      yro   rp   r:   s    r3   can_signzRsaKey.can_sign   rr   r5   c                 D    t        | j                  | j                        S )z^A matching RSA public key.

        Returns:
            a new :class:`RsaKey` object
        r   )r   r9   r=   r:   s    r3   
public_keyzRsaKey.public_key   s     477++r5   c                     | j                         |j                         k7  ry| j                  |j                  k7  s| j                  |j                  k7  ry| j                         sy| j                  |j                  k(  S )NFT)r?   r   r   r   r,   others     r3   __eq__zRsaKey.__eq__   sc    !2!2!4466UWW%'' 1!%''!"r5   c                     | |k(   S r7   rp   rx   s     r3   __ne__zRsaKey.__ne__   s    EM""r5   c                     ddl m} |)Nr   )PicklingError)pickler~   )r,   r~   s     r3   __getstate__zRsaKey.__getstate__   s    (r5   c                 .   | j                         rVdt        | j                        t        | j                        t        | j                        t        | j
                        fz  }nd}dt        | j                        t        | j                        |fz  S )Nz, d=%d, p=%d, q=%d, u=%d zRsaKey(n=%d, e=%d%s))r?   r8   r&   r'   r)   rO   r9   r=   )r,   extras     r3   __repr__zRsaKey.__repr__   sq    .#dgg,DGG25dgg,DGG2N NE E%TWWs477|U(KKKr5   c                 L    | j                         rd}nd}d|t        |       fz  S )NPrivatePublicz%s RSA key at 0x%X)r?   id)r,   key_types     r3   __str__zRsaKey.__str__   s,     HH#xD&:::r5   Nc                 d   |t        |      }|t        j                  }|dk(  r| j                  | j                  fD cg c]  }|j                          c}\  }}	t        |d         dz  rd|z   }t        |	d         dz  rd|	z   }	d||	g}
dj                  |
D cg c]$  }t        j                  dt        |            |z   & c}      }d	t        j                  |      dd
 z   S | j                         r7t        d| j                  | j                   | j"                  | j$                  | j&                  | j"                  | j$                  dz
  z  | j"                  | j&                  dz
  z  t)        | j&                        j+                  | j$                        g	      j-                         }|dk(  rd}|dk(  r|rt/        d      ddlm} |dk(  r&|$d}|j5                  |t6        dt9                     }nsd}|s|rt/        d      d}|j5                  |t6        |||t9                     }d}n:d}t;        t6        t        | j                  | j                   g      t9                     }|dk(  r|S |dk(  r%ddlm} |j-                  ||||      }t        |      S t/        d|z        c c}w c c}w )a  Export this RSA key.

        Keyword Args:
          format (string):
            The desired output format:

            - ``'PEM'``. (default) Text output, according to `RFC1421`_/`RFC1423`_.
            - ``'DER'``. Binary output.
            - ``'OpenSSH'``. Text output, according to the OpenSSH specification.
              Only suitable for public keys (not private keys).

            Note that PEM contains a DER structure.

          passphrase (bytes or string):
            (*Private keys only*) The passphrase to protect the
            private key.

          pkcs (integer):
            (*Private keys only*) The standard to use for
            serializing the key: PKCS#1 or PKCS#8.

            With ``pkcs=1`` (*default*), the private key is encoded with a
            simple `PKCS#1`_ structure (``RSAPrivateKey``). The key cannot be
            securely encrypted.

            With ``pkcs=8``, the private key is encoded with a `PKCS#8`_ structure
            (``PrivateKeyInfo``). PKCS#8 offers the best ways to securely
            encrypt the key.

            .. note::
                This parameter is ignored for a public key.
                For DER and PEM, the output is always an
                ASN.1 DER ``SubjectPublicKeyInfo`` structure.

          protection (string):
            (*For private keys only*)
            The encryption scheme to use for protecting the private key
            using the passphrase.

            You can only specify a value if ``pkcs=8``.
            For all possible protection schemes,
            refer to :ref:`the encryption parameters of PKCS#8<enc_params>`.
            The recommended value is
            ``'PBKDF2WithHMAC-SHA512AndAES256-CBC'``.

            If ``None`` (default), the behavior depends on :attr:`format`:

            - if ``format='PEM'``, the obsolete PEM encryption scheme is used.
              It is based on MD5 for key derivation, and 3DES for encryption.

            - if ``format='DER'``, the ``'PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC'``
              scheme is used.

          prot_params (dict):
            (*For private keys only*)

            The parameters to use to derive the encryption key
            from the passphrase. ``'protection'`` must be also specified.
            For all possible values,
            refer to :ref:`the encryption parameters of PKCS#8<enc_params>`.
            The recommendation is to use ``{'iteration_count':21000}`` for PBKDF2,
            and ``{'iteration_count':131072}`` for scrypt.

          randfunc (callable):
            A function that provides random bytes. Only used for PEM encoding.
            The default is :func:`Crypto.Random.get_random_bytes`.

        Returns:
          bytes: the encoded key

        Raises:
          ValueError:when the format is unknown or when you try to encrypt a private
            key with *DER* format and PKCS#1.

        .. warning::
            If you don't provide a pass phrase, the private key will be
            exported in the clear!

        .. _RFC1421:    http://www.ietf.org/rfc/rfc1421.txt
        .. _RFC1423:    http://www.ietf.org/rfc/rfc1423.txt
        .. _`PKCS#1`:   http://www.ietf.org/rfc/rfc3447.txt
        .. _`PKCS#8`:   http://www.ietf.org/rfc/rfc5208.txt
        NOpenSSHr          s   ssh-rsar5   >I   ssh-rsa r    zRSA PRIVATE KEYDERz&PKCS#1 private key cannot be encryptedPKCS8PEMzPRIVATE KEY)
key_paramszENCRYPTED PRIVATE KEYz"'protection' parameter must be setz"PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC)prot_paramsr   z
PUBLIC KEYr   z3Unknown key format '%s'. Cannot export the RSA key.)r	   r   get_random_bytesr=   r9   to_bytesr
   joinstructpacklenbinascii
b2a_base64r?   r   r   r   r   r   r   r   rJ   encoder#   	Crypto.IOr   wrapr   r   r   r   )r,   format
passphrasepkcs
protectionrandfuncr   xe_bytesn_byteskeypartskp	keystring
binary_keyr   r   r   pem_strs                     r3   
export_keyzRsaKey.export_key  s   l ! ,J..HY7;ww6HI

IGWGAJ$&!G+GAJ$&!G+"GW5HH!Ub&++dCG"<r"A!UVI!4!4Y!?!DDD $a&*ff&*ff&*ff&*ff&*ff&*ffq&9&*ffq&9&-dffo&=&=dff&E	&( 	) *0  qy,U?z$%MNN+U?z'9,H!&JT7>y ", "BJ  7H%&",-Q"RR%I
!&J,6
8C7>y ", "BJ "&J#H89DdffFJffFN :O9@;J U?U?%jjXz8LG7##NQWWXXy  J "Vs   J()J-c                 &     | j                   |i |S :meta private:)r   )r,   argsr-   s      r3   	exportKeyzRsaKey.exportKey  s    t///r5   c                 "    | j                         S r   )rv   r:   s    r3   	publickeyzRsaKey.publickey  s      r5   c                     t        d      r   z,Use module Crypto.Signature.pkcs1_15 insteadNotImplementedError)r,   MKs      r3   signzRsaKey.sign      !"PQQr5   c                     t        d      r   r   )r,   r   	signatures      r3   verifyzRsaKey.verify  r   r5   c                     t        d      r   z+Use module Crypto.Cipher.PKCS1_OAEP insteadr   )r,   rX   r   s      r3   encryptzRsaKey.encrypt      !"OPPr5   c                     t        d      r   r   rj   s     r3   decryptzRsaKey.decrypt  r   r5   c                     t         r   r   r,   r   Bs      r3   blindzRsaKey.blind      !!r5   c                     t         r   r   r   s      r3   unblindzRsaKey.unblind  r   r5   c                     t         r   r   r:   s    r3   sizezRsaKey.size  r   r5   )r   Nr    NNN)(__name__
__module____qualname____doc__r4   propertyr   r   r   r   r   rE   rH   rK   rM   r   rR   rU   rY   rh   rk   r?   rq   rt   rv   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   rp   r5   r3   r   r   4   s]   :>      
  
  
  
  
      
&5>
2A
#
,##
L; >??CYYx0!
RRQQ"""r5   r   c                    | dk  rt        d      dz  dk(  sdk  rt        d      |t        j                  }t        d      x}}t              |j	                         | k7  r|d| dz  z  k  r| dz  }| |z
  }t        d      d|z  dz
  z  j                         x||k7  r"t        d      d|z  dz
  z  j                         fd}t        |||	      t        d      | dz  d
z
  z  fd}t        |||	      }	|	z  }dz
  j                  |	dz
        }
j                  |
      }|j	                         | k7  r|d| dz  z  k  r߉	kD  r|	c}	j                  |	      }t        |||	|      S )aB  Create a new RSA key pair.

    The algorithm closely follows NIST `FIPS 186-4`_ in its
    sections B.3.1 and B.3.3. The modulus is the product of
    two non-strong probable primes.
    Each prime passes a suitable number of Miller-Rabin tests
    with random bases and a single Lucas test.

    Args:
      bits (integer):
        Key length, or size (in bits) of the RSA modulus.
        It must be at least 1024, but **2048 is recommended.**
        The FIPS standard only defines 1024, 2048 and 3072.
    Keyword Args:
      randfunc (callable):
        Function that returns random bytes.
        The default is :func:`Crypto.Random.get_random_bytes`.
      e (integer):
        Public RSA exponent. It must be an odd positive integer.
        It is typically a small number with very few ones in its
        binary representation.
        The FIPS standard requires the public exponent to be
        at least 65537 (the default).

    Returns: an RSA key object (:class:`RsaKey`, with private key).

    .. _FIPS 186-4: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
    i   z"RSA modulus length must be >= 1024   r      zBRSA public exponent must be a positive, odd integer larger than 2.r    c                 @    | kD  xr | dz
  j                        dk(  S Nr    )gcd)	candidater   min_ps    r3   filter_pzgenerate.<locals>.filter_p  s'    u$D)a-)<)<Q)?1)DDr5   )
exact_bitsr   prime_filterd   c                 f    | kD  xr* | dz
  j                        dk(  xr t        | z
        kD  S r   )r   abs)r   r   min_distancemin_qr   s    r3   filter_qzgenerate.<locals>.filter_q  sB    % 6]''*a/6	A&57r5   r   r   r   r   r   r   )
r#   r   r   r   rR   sqrtr   lcmrJ   r   )bitsr   r   r   r   size_qsize_pr   r   r   r   r   r   r   r   r   s     `         @@@@r3   r   r     s   < d{=>>1uzQU]^^**AJA
A
..
d
"qA$!),<'=  F
Q7==??VQZAJN399;E	E $v-519; qzdai#o6	7
 $v-519; E1ukk!a% IIcN? ..
d
"qA$!),<'=B 	1u!1			!AAa1Q//r5   c                     G d dt               } |       }t        d|       D ]  \  }}t        ||t        |              |j                  }|j
                  }t        |d      st        ||      }n.|j                  }	t        |d      r|j                  }
|j                  }n|	|z  dz
  }|}|dz  d	k(  r|dz  }|dz  d	k(  rd
}t        d      }|sw|dk  rrt        |      }||k  rUt        |||      }|dk7  r8||dz
  k7  r0t        |d|      dk(  r t        |      j                  |dz         }
d}n|dz  }||k  rU|dz  }|s|dk  rr|st        d      |
z  d	k(  sJ ||
z  }t        |d      r|j                  }n|
j                  |      }t        |||	|
||      }|rc|dk  s||k\  rt        d      t        |      j                  |      dk7  rt        d      |dz  st        d      |j!                         r	dk  s|	|k\  rt        d      t        |      j                  |	      dk7  rt        d      
z  |k7  rt        d      t#        |
      t$        k(  rt        d      t#        |      t$        k(  rt        d      |
dz
  |dz
  z  }||
dz
  j                  |dz
        z  }||	z  t'        |      z  dk7  rt        d      t        |d      r+dk  s||k\  rt        d      |
|z  |z  dk7  rt        d      |S )a3  Construct an RSA key from a tuple of valid RSA components.

    The modulus **n** must be the product of two primes.
    The public exponent **e** must be odd and larger than 1.

    In case of a private key, the following equations must apply:

    .. math::

        \begin{align}
        p*q &= n \\
        e*d &\equiv 1 ( \text{mod lcm} [(p-1)(q-1)]) \\
        p*u &\equiv 1 ( \text{mod } q)
        \end{align}

    Args:
        rsa_components (tuple):
            A tuple of integers, with at least 2 and no
            more than 6 items. The items come in the following order:

            1. RSA modulus *n*.
            2. Public exponent *e*.
            3. Private exponent *d*.
               Only required if the key is private.
            4. First factor of *n* (*p*).
               Optional, but the other factor *q* must also be present.
            5. Second factor of *n* (*q*). Optional.
            6. CRT coefficient *q*, that is :math:`p^{-1} \text{mod }q`. Optional.

    Keyword Args:
        consistency_check (boolean):
            If ``True``, the library will verify that the provided components
            fulfil the main RSA properties.

    Raises:
        ValueError: when the key being imported fails the most basic RSA validity checks.

    Returns: An RSA key object (:class:`RsaKey`).
    c                       e Zd Zy)construct.<locals>.InputCompsN)r   r   r   rp   r5   r3   
InputCompsr   D  s    r5   r   r   r   r   r   r    r   r   Fr   Tz2Unable to compute factors p and q from exponent d.r   zInvalid RSA public exponentz-RSA public exponent is not coprime to moduluszRSA modulus is not oddzInvalid RSA private exponentz.RSA private exponent is not coprime to modulusz RSA factors do not match moduluszRSA factor p is compositezRSA factor q is compositezInvalid RSA conditionzInvalid RSA component uzInvalid RSA component u with p)objectzipr%   r   r   r   rm   r   r   r   r   rW   r   r#   r   rJ   r?   r   r   r8   )rsa_componentsconsistency_checkr   input_compscompr2   r   r   keyr   r   r   ktottspottedakcandr   phir   s                        r3   r   r     s:   RV  ,K;^L 3uT75>23 	AA;$qAMM;$AA
 q519D Aa%1*a a%1* G
A!c'AJ$hq!Q<DqyTa!e_T1aA9M $AJNN4!84"&FA $h Q !c'  !UVVUqL!QA;$A		!A qAa12  6Q!V:;;1:>>!!LMM 1u566??Ava !?@@qz~~a A% !QRR1uz !CDD"1%2 !<=="1%2 !<==q5QU#C!a%QU++CAC Q& !899sC 6Q!V$%>??EAI!#$%EFFJr5   c                     t               j                  | dd      }|d   dk7  rt        d      t        |dd t	        |d         j                  |d	         gz         S )
N	   Tnr_elementsonly_ints_expectedr   z(No PKCS#1 encoding of an RSA private keyr             )r   decoder#   r   r   rJ   encodedr-   ders      r3   _import_pkcs1_privater    sd     -

wA$

OC
1v{CDDS1XQ!8!8Q!@ AABBr5   c                 P    t               j                  | dd      }t        |      S )Nr   Tr  )r   r	  r   r
  s      r3   _import_pkcs1_publicr    s'    
 -

wA$

OCS>r5   c                 h    t         df}t        |       \  }}}||vs|t        d      t        |      S )N1.2.840.113549.1.1.10zNo RSA subjectPublicKeyInfo)r   r   r#   r  )r  r-   oidsalgoidencoded_keyparamss         r3   _import_subjectPublicKeyInfor    sB    ()D"A'"JFKTV/677,,r5   c                 .    t        |       }t        |      S r7   )r   r  )r  r-   sp_infos      r3   _import_x509_certr    s    .w7G'00r5   c                     ddl m} t        df}|j                  | |      }|d   |vrt	        d      t        |d   |      S )Nr   r   r  zNo PKCS#8 encoded RSA keyr    )r   r   r   unwrapr#   _import_keyDER)r  r   r   r  r   s        r3   _import_pkcs8r    sI    ()DWj)At4455!A$
++r5   c                     t         t        t        t        t        f}|D ]  }	  || |      c S  t        d      # t
        $ r Y &w xY w)z@Import an RSA key (public or private half), encoded in DER form.RSA key format is not supported)r  r  r  r  r  r#   )
extern_keyr   	decodingsdecodings       r3   r  r    s_     '%-"	 I  	J
33 6
77  		s   9	AAc                 l   ddl m}m}m}m}  || |      \  }}|dk7  rt        d       ||      \  }} ||      \  }	} ||      \  }
} ||      \  }} ||      \  }} ||      \  }} ||      \  }} ||       ||	|
|||fD cg c]  }t        j                  |       }}t        |      S c c}w )Nr    )import_openssh_private_generic
read_bytesread_stringcheck_paddingzssh-rsazThis SSH key is not RSA)	_opensshr$  r%  r&  r'  r#   r   
from_bytesr   )datapasswordr$  r%  r&  r'  ssh_name	decryptedr   r   r   iqmpr   r   r   paddedr   builds                     r3   _import_openssh_private_rsar1    s    C C 9xHHi9233i(LAyi(LAyi(LAy +OD)i(LAyi(LAyI&IAv&-.1aD,ABqW"BEBU Cs   B1c                 H   ddl m} t        |       } |t        |      }| j                  d      r/t	        |       }|j                  ||      \  }}}t        ||      }|S | j                  d      r/|j                  t	        |       |      \  }}}|rd}t        ||      S | j                  d      rt        j                  | j                  d      d         }	g }
t        |	      d	kD  rJt        j                  d
|	dd	       d   }|
j                  |	d	d	|z           |	d	|z   d }	t        |	      d	kD  rJt        j                   |
d         }t        j                   |
d         }t#        ||g      S t        |       dkD  rt%        | d         dk(  rt        | |      S t'        d      )a  Import an RSA key (public or private).

    Args:
      extern_key (string or byte string):
        The RSA key to import.

        The following formats are supported for an RSA **public key**:

        - X.509 certificate (binary or PEM format)
        - X.509 ``subjectPublicKeyInfo`` DER SEQUENCE (binary or PEM
          encoding)
        - `PKCS#1`_ ``RSAPublicKey`` DER SEQUENCE (binary or PEM encoding)
        - An OpenSSH line (e.g. the content of ``~/.ssh/id_ecdsa``, ASCII)

        The following formats are supported for an RSA **private key**:

        - PKCS#1 ``RSAPrivateKey`` DER SEQUENCE (binary or PEM encoding)
        - `PKCS#8`_ ``PrivateKeyInfo`` or ``EncryptedPrivateKeyInfo``
          DER SEQUENCE (binary or PEM encoding)
        - OpenSSH (text format, introduced in `OpenSSH 6.5`_)

        For details about the PEM encoding, see `RFC1421`_/`RFC1423`_.

      passphrase (string or byte string):
        For private keys only, the pass phrase that encrypts the key.

    Returns: An RSA key object (:class:`RsaKey`).

    Raises:
      ValueError/IndexError/TypeError:
        When the given key cannot be parsed (possibly because the pass
        phrase is wrong).

    .. _RFC1421: http://www.ietf.org/rfc/rfc1421.txt
    .. _RFC1423: http://www.ietf.org/rfc/rfc1423.txt
    .. _`PKCS#1`: http://www.ietf.org/rfc/rfc3447.txt
    .. _`PKCS#8`: http://www.ietf.org/rfc/rfc5208.txt
    .. _`OpenSSH 6.5`: https://flak.tedunangst.com/post/new-openssh-key-format-and-bcrypt-pbkdf
    r   r   Ns   -----BEGIN OPENSSH PRIVATE KEYs   -----r       r    r  r   r   0   r  )r   r   r	   
startswithr   r	  r1  r  r   
a2b_base64splitr   r   unpackappendr   r)  r   r
   r#   )r   r   r   text_encodedopenssh_encodedmarkerenc_flagrg   r  r   r   lengthr   r   s                 r3   r   r     s   R $JZ(
>?Z(,/JJ|Z,P),_jIX&"%**U:->
"KfhJc:..[)''
(8(8(>q(AB	)nq ]]42A7:FOOIaF
34!!f*+.I )nq  x{+x{+!Q  
:tJqM2d:j*55
6
77r5   z1.2.840.113549.1.1.1)Ni  )Tr7   )&__all__r   r   Cryptor   Crypto.Util.py3compatr	   r
   r   Crypto.Util.asn1r   r   Crypto.Util.numberr   Crypto.Math.Numbersr   Crypto.Math.Primalityr   r   r   Crypto.PublicKeyr   r   r   r   r   r   r   r  r  r  r  r  r  r1  r   	importKeyr   rp   r5   r3   <module>rH     s   @    6 6 1 , 'G G@ @
R"V R"jO0dM`C(-1,8$0L8` 	 r5   