
    hg8                      U d dl mZ d dlZd dlZd dlZd dlZd dlZd dl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 d d	lmZmZmZmZ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% d dlm&Z' g dZ(eej)        ej*        ej+        ej,        ej-        f         Z.eej/        ej0        ej1        ej2        ej3        f         Z4ee.e4f         Z5ee6e7ef         Z8ee7ede7f         f         Z9e#j:        Z;de<d<   e#j=        Z>de<d<   dZ?e#j@        ZAde<d<   e#jB        ZCde<d<   e#jD        ZEde<d<   e#jF        ZGde<d<    G d deH          ZI eeeI          ZJ e%eI          ZKdbdcd ZLddd#ZMded'ZNdfd(ZOdgd*ZP G d+ d,          ZQ G d- d.          ZR G d/ d0          ZSdhd2ZTeTZU ejV        eTeWd3eXd45           did8ZY ejV        eYeWd9eXd:5           ejZ         G d; d<                      Z[ G d= d>          Z\e\Z] ejV        e\eWd?eXd>5            G d@ dA          Z^e^Z_ ejV        e^eWdBeXdA5            G dC dD          Z` G dE dF          Za G dG dH          Zb G dI dJeH          Zc G dK dL          ZddjdNZedkdPZfdldRZg	 	 dmdndWZh G dX dY          Zidod[Zj	 dbdpd\Zkdqd^ZlelZm ejV        eleWdBeXd_5           drd`ZnenZo ejV        eneWdBeXda5           dS )s    )annotationsN)	b16encode)IterableSequence)partial)PathLike)AnyCallableUnion)utilsx509)dsaeced448ed25519rsa)byte_string)exception_from_error_queue)ffi)lib)make_assert)
path_bytes)FILETYPE_ASN1FILETYPE_PEMFILETYPE_TEXTTYPE_DSATYPE_RSAX509ErrorPKeyX509ExtensionX509NameX509Req	X509StoreX509StoreContextX509StoreContextErrorX509StoreFlagsdump_certificatedump_certificate_requestdump_privatekeydump_publickeyget_elliptic_curveget_elliptic_curvesload_certificateload_certificate_requestload_privatekeyload_publickey.intr   r   i  r   r   TYPE_DHTYPE_ECc                      e Zd ZdZdS )r   z7
    An error occurred in an `OpenSSL.crypto` API.
    N)__name__
__module____qualname____doc__     G/var/www/fb-scrape/myenv/lib/python3.11/site-packages/OpenSSL/crypto.pyr   r   j   s           r;   r   bufferbytes | Nonereturnr	   c                L   | 2t          j        t          j                              }t           j        }n=t	          j        d|           }t          j        |t          |                     }|fdd}t          |t          j	        k               t	          j
        ||          }|S )	z
    Allocate a new OpenSSL memory BIO.

    Arrange for the garbage collector to clean it up automatically.

    :param buffer: None or some bytes to use to put into the BIO so that they
        can be read out.
    Nchar[]bior	   refr?   c                *    t          j        |           S N)_libBIO_free)rB   rC   s     r<   freez_new_mem_buf.<locals>.free   s    =%%%r;   )rB   r	   rC   r	   r?   r	   )rF   BIO_new	BIO_s_memrG   _ffinewBIO_new_mem_buflen_openssl_assertNULLgc)r=   rB   rH   datas       r<   _new_mem_bufrS   t   s     ~l4>++,,}x&))"4V55 '+ 	& 	& 	& 	& 	& C49$%%%
'#t

CJr;   rB   bytesc                    t          j        d          }t          j        | |          }t          j        |d         |          dd         S )zO
    Copy the contents of an OpenSSL BIO object into a Python byte string.
    zchar**r   N)rK   rL   rF   BIO_get_mem_datar=   )rB   result_bufferbuffer_lengths      r<   _bio_to_stringrY      sE     HX&&M)#}==M;}Q'77::r;   boundarywhenNonec                    t          |t                    st          d          t          | t          j        k               t          j        | |          }|dk    rt          d          dS )a  
    The the time value of an ASN1 time object.

    @param boundary: An ASN1_TIME pointer (or an object safely
        castable to that type) which will have its value set.
    @param when: A string representation of the desired time value.

    @raise TypeError: If C{when} is not a L{bytes} string.
    @raise ValueError: If C{when} does not represent a time in the required
        format.
    @raise RuntimeError: If the time value cannot be set for some other
        (unspecified) reason.
    zwhen must be a byte stringr   zInvalid stringN)	
isinstancerT   	TypeErrorrO   rK   rP   rF   ASN1_TIME_set_string
ValueError)rZ   r[   
set_results      r<   _set_asn1_timerc      sm     dE"" 64555 H	)****8T::JQ)*** r;   c                    t          j                    }t          |t          j        k               t          j        |t           j                  }t          ||            |S )a  
    Behaves like _set_asn1_time but returns a new ASN1_TIME object.

    @param when: A string representation of the desired time value.

    @raise TypeError: If C{when} is not a L{bytes} string.
    @raise ValueError: If C{when} does not represent a time in the required
        format.
    @raise RuntimeError: If the time value cannot be set for some other
        (unspecified) reason.
    )rF   ASN1_TIME_newrO   rK   rP   rQ   ASN1_TIME_freerc   )r[   rets     r<   _new_asn1_timerh      sP     


CC49$%%%
'#t*
+
+C3Jr;   	timestampc                F   t          j        d|           }t          j        |          dk    rdS t          j        |          t          j        k    r&t          j        t          j        |                    S t          j        d          }t          j	        | |           t          |d         t           j        k               t          j        d|d                   }t          j        |          }t          j        |          }t          j        |d                    |S )a]  
    Retrieve the time value of an ASN1 time object.

    @param timestamp: An ASN1_GENERALIZEDTIME* (or an object safely castable to
        that type) from which the time value will be retrieved.

    @return: The time value from C{timestamp} as a L{bytes} string in a certain
        format.  Or C{None} if the object contains no time value.
    ASN1_STRING*r   NzASN1_GENERALIZEDTIME**)rK   castrF   ASN1_STRING_lengthASN1_STRING_typeV_ASN1_GENERALIZEDTIMEstringASN1_STRING_get0_datarL   ASN1_TIME_to_generalizedtimerO   rP   ASN1_GENERALIZEDTIME_free)ri   string_timestampgeneralized_timestampstring_datastring_results        r<   _get_asn1_timerx      s     y;;/00A55t.//43NNN{456FGGHHH $)A B B))5JKKK-a0DI=>>>9^5J15MNN01ABBK00&'<Q'?@@@r;   c                  &    e Zd Zd	dZd
dZd	dZdS )_X509NameInvalidatorr?   r\   c                    g | _         d S rE   )_namesselfs    r<   __init__z_X509NameInvalidator.__init__   s    &(r;   namer"   c                :    | j                             |           d S rE   )r|   appendr~   r   s     r<   addz_X509NameInvalidator.add   s    4     r;   c                    | j         D ]}|`d S rE   )r|   _namer   s     r<   clearz_X509NameInvalidator.clear   s$    K 	 	D

	 	r;   Nr?   r\   r   r"   r?   r\   )r6   r7   r8   r   r   r   r:   r;   r<   rz   rz      sP        ) ) ) )! ! ! !     r;   rz   c                  b    e Zd ZdZdZdZddZddZedd
            Z	ddZ
ddZddZddZdS )r    zD
    A class representing an DSA or RSA public key or key pair.
    FTr?   r\   c                    t          j                    }t          j        |t           j                  | _        d| _        d S )NF)rF   EVP_PKEY_newrK   rQ   EVP_PKEY_free_pkey_initializedr~   pkeys     r<   r   zPKey.__init__   s4     ""WT4#566
!r;   _Keyc                    ddl m}m} | j        r t	          t
          |           } ||          S t          t
          |           } ||d          S )a  
        Export as a ``cryptography`` key.

        :rtype: One of ``cryptography``'s `key interfaces`_.

        .. _key interfaces: https://cryptography.io/en/latest/hazmat/            primitives/asymmetric/rsa/#key-interfaces

        .. versionadded:: 16.1.0
        r   )load_der_private_keyload_der_public_keyN),cryptography.hazmat.primitives.serializationr   r   _only_publicr+   r   r*   )r~   r   r   ders       r<   to_cryptography_keyzPKey.to_cryptography_key   sy    	
 	
 	
 	
 	
 	
 	
 	

  	3 55C&&s+++!-66C''T222r;   
crypto_keyc                   t          |t          j        t          j        t          j        t          j        t          j        t          j	        t          j        t          j        t          j        t          j        f
          st!          d          ddlm}m}m}m} t          |t          j        t          j        t          j	        t          j        t          j        f          r3t-          t.          |                    |j        |j                            S |                    |j        |j         |                      }t;          t.          |          S )z
        Construct based on a ``cryptography`` *crypto_key*.

        :param crypto_key: A ``cryptography`` key.
        :type crypto_key: One of ``cryptography``'s `key interfaces`_.

        :rtype: PKey

        .. versionadded:: 16.1.0
        zUnsupported key typer   )EncodingNoEncryptionPrivateFormatPublicFormat)r^   r   DSAPrivateKeyDSAPublicKeyr   EllipticCurvePrivateKeyEllipticCurvePublicKeyr   Ed25519PrivateKeyEd25519PublicKeyr   Ed448PrivateKeyEd448PublicKeyr   RSAPrivateKeyRSAPublicKeyr_   r   r   r   r   r   r1   r   public_bytesDERSubjectPublicKeyInfoprivate_bytesPKCS8r0   )clsr   r   r   r   r   r   s          r<   from_cryptography_keyzPKey.from_cryptography_key  sP    ! *))(%$! 
 
 	4 2333	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
  )($ 	
 	
 	7 "''L,"C    **m1<<>> C #=#666r;   typer2   bitsc           	        t          |t                    st          d          t          |t                    st          d          |t          k    r|dk    rt	          d          t          j                    }t          j        |t
          j	                  }t          j
        |t
          j                   t          j                    }t          j        |||t          j                  }t          |dk               t          j        | j        |          }t          |dk               n|t$          k    rt          j                    }t          |t          j        k               t          j        |t
          j                  }t          j        ||t          j        dt          j        t          j        t          j                  }t          |dk               t          t          j        |          dk               t          t          j        | j        |          dk               nt1          d          d| _        dS )	a3  
        Generate a key pair of the given type, with the given number of bits.

        This generates a key "into" the this object.

        :param type: The key type.
        :type type: :py:data:`TYPE_RSA` or :py:data:`TYPE_DSA`
        :param bits: The number of bits.
        :type bits: :py:data:`int` ``>= 0``
        :raises TypeError: If :py:data:`type` or :py:data:`bits` isn't
            of the appropriate type.
        :raises ValueError: If the number of bits isn't an integer of
            the appropriate size.
        :return: ``None``
        ztype must be an integerzbits must be an integerr   zInvalid number of bits   zNo such key typeTN)r^   r2   r_   r   ra   rF   BN_newrK   rQ   BN_freeBN_set_wordRSA_F4RSA_newRSA_generate_key_exrP   rO   EVP_PKEY_assign_RSAr   r   DSA_newDSA_freeDSA_generate_parameters_exDSA_generate_keyEVP_PKEY_set1_DSAr   r   )r~   r   r   exponentr   resultr   ress           r<   generate_keyzPKey.generate_keyK  s     $$$ 	75666$$$ 	756668qyy !9::: {}}Hwx66HXt{333,..C-c449MMFFaK(((-dj#>>FFaK((((X,..CC49,---'#t}--C1T49aDIty C C1H%%%D1#66!;<<<D24:sCCqHIIII*+++ r;   boolc                |   | j         rt          d          t          j        |                                           t          j        k    rt          d          t          j        | j                  }t          j	        |t          j
                  }t          j        |          }|dk    rdS t                       dS )ax  
        Check the consistency of an RSA private key.

        This is the Python equivalent of OpenSSL's ``RSA_check_key``.

        :return: ``True`` if key is consistent.

        :raise OpenSSL.crypto.Error: if the key is inconsistent.

        :raise TypeError: if the key is of a type which cannot be checked.
            Only RSA keys can currently be checked.
        zpublic key onlyz'Only RSA keys can currently be checked.r   TN)r   r_   rF   EVP_PKEY_typer   EVP_PKEY_RSAEVP_PKEY_get1_RSAr   rK   rQ   RSA_freeRSA_check_key_raise_current_error)r~   r   r   s      r<   checkz
PKey.check  s      	/-...diikk**d.???EFFF$TZ00gc4=))#C((Q;;4r;   c                4    t          j        | j                  S )zT
        Returns the type of the key

        :return: The type of the key.
        )rF   EVP_PKEY_idr   r}   s    r<   r   z	PKey.type  s     
+++r;   c                4    t          j        | j                  S )zh
        Returns the number of bits of the key

        :return: The number of bits of the key.
        )rF   EVP_PKEY_bitsr   r}   s    r<   r   z	PKey.bits  s     !$*---r;   Nr   )r?   r   )r   r   r?   r    )r   r2   r   r2   r?   r\   r?   r   r?   r2   )r6   r7   r8   r9   r   r   r   r   classmethodr   r   r   r   r   r:   r;   r<   r    r       s          LL" " " "
3 3 3 3. 77 77 77 [77r6! 6! 6! 6!p   4, , , ,. . . . . .r;   r    c                       e Zd ZdZdZd fdZedd
            Zedd            Zedd            Z	ddZ
ddZddZ xZS )_EllipticCurveaZ  
    A representation of a supported elliptic curve.

    @cvar _curves: :py:obj:`None` until an attempt is made to load the curves.
        Thereafter, a :py:type:`set` containing :py:type:`_EllipticCurve`
        instances each of which represents one curve supported by the system.
    @type _curves: :py:type:`NoneType` or :py:type:`set`
    Notherr	   r?   r   c                ~    t          |t                    r!t                                          |          S t          S )z
        Implement cooperation with the right-hand side argument of ``!=``.

        Python 3 seems to have dropped this cooperation in this very narrow
        circumstance.
        )r^   r   super__ne__NotImplemented)r~   r   	__class__s     r<   r   z_EllipticCurve.__ne__  s3     e^,, 	)77>>%(((r;   r   set[_EllipticCurve]c                                          t          j        d          }t          j        d|          }                     ||           t	           fd|D                       S )z
        Get the curves supported by OpenSSL.

        :param lib: The OpenSSL library binding object.

        :return: A :py:type:`set` of ``cls`` instances giving the names of the
            elliptic curves the underlying library supports.
        r   zEC_builtin_curve[]c              3  N   K   | ]}                     |j                  V   d S rE   )from_nidnid).0cr   r   s     r<   	<genexpr>z7_EllipticCurve._load_elliptic_curves.<locals>.<genexpr>  s3      DD3<<QU++DDDDDDr;   )EC_get_builtin_curvesrK   rP   rL   set)r   r   
num_curvesbuiltin_curvess   ``  r<   _load_elliptic_curvesz$_EllipticCurve._load_elliptic_curves  sm     ..ty!<<
"6
CC 	!!.*===DDDDD^DDDDDDr;   c                R    | j         |                     |          | _         | j         S )a  
        Get, cache, and return the curves supported by OpenSSL.

        :param lib: The OpenSSL library binding object.

        :return: A :py:type:`set` of ``cls`` instances giving the names of the
            elliptic curves the underlying library supports.
        )_curvesr   )r   r   s     r<   _get_elliptic_curvesz#_EllipticCurve._get_elliptic_curves  s)     ;33C88CK{r;   r   r2   c           	          | ||t          j        |                    |                                        d                    S )a  
        Instantiate a new :py:class:`_EllipticCurve` associated with the given
        OpenSSL NID.

        :param lib: The OpenSSL library binding object.

        :param nid: The OpenSSL NID the resulting curve object will represent.
            This must be a curve NID (and not, for example, a hash NID) or
            subsequent operations will fail in unpredictable ways.
        :type nid: :py:class:`int`

        :return: The curve object.
        ascii)rK   rp   
OBJ_nid2sndecode)r   r   r   s      r<   r   z_EllipticCurve.from_nid  s<     s3T[)<)<==DDWMMNNNr;   r   strr\   c                0    || _         || _        || _        dS )a  
        :param _lib: The :py:mod:`cryptography` binding instance used to
            interface with OpenSSL.

        :param _nid: The OpenSSL NID identifying the curve this object
            represents.
        :type _nid: :py:class:`int`

        :param name: The OpenSSL short name identifying the curve this object
            represents.
        :type name: :py:class:`unicode`
        N)rF   _nidr   )r~   r   r   r   s       r<   r   z_EllipticCurve.__init__  s     					r;   c                    d| j         dS )Nz<Curve >r   r}   s    r<   __repr__z_EllipticCurve.__repr__  s    '''''r;   c                ~    | j                             | j                  }t          j        |t           j                  S )z
        Create a new OpenSSL EC_KEY structure initialized to use this curve.

        The structure is automatically garbage collected when the Python object
        is garbage collected.
        )rF   EC_KEY_new_by_curve_namer   rK   rQ   EC_KEY_free)r~   keys     r<   
_to_EC_KEYz_EllipticCurve._to_EC_KEY
  s0     i00;;wsD,---r;   r   r	   r?   r   )r   r	   r?   r   )r   r	   r   r2   r?   r   )r   r	   r   r2   r   r   r?   r\   r?   r   r?   r	   )r6   r7   r8   r9   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r<   r   r     s          G	 	 	 	 	 	 E E E [E"    [ O O O [O    "( ( ( (. . . . . . . .r;   r   r   c                 @    t                               t                    S )a  
    Return a set of objects representing the elliptic curves supported in the
    OpenSSL build in use.

    The curve objects have a :py:class:`unicode` ``name`` attribute by which
    they identify themselves.

    The curve objects are useful as values for the argument accepted by
    :py:meth:`Context.set_tmp_ecdh` to specify which elliptical curve should be
    used for ECDHE key exchange.
    )r   r   rF   r:   r;   r<   r-   r-     s     ..t444r;   zSget_elliptic_curves is deprecated. You should use the APIs in cryptography instead.r-   r   r   r   c                b    t                      D ]}|j        | k    r|c S t          d|           )aT  
    Return a single curve object selected by name.

    See :py:func:`get_elliptic_curves` for information about curve objects.

    :param name: The OpenSSL short name identifying the curve object to
        retrieve.
    :type name: :py:class:`unicode`

    If the named curve is not supported then :py:class:`ValueError` is raised.
    zunknown curve name)_get_elliptic_curves_internalr   ra   )r   curves     r<   r,   r,   2  sE     /00  :LLL 
)4
0
00r;   zRget_elliptic_curve is deprecated. You should use the APIs in cryptography instead.r,   c                  d     e Zd ZdZddZd fd	ZddZddZddZddZ	ddZ
ddZddZ xZS )r"   a  
    An X.509 Distinguished Name.

    :ivar countryName: The country of the entity.
    :ivar C: Alias for  :py:attr:`countryName`.

    :ivar stateOrProvinceName: The state or province of the entity.
    :ivar ST: Alias for :py:attr:`stateOrProvinceName`.

    :ivar localityName: The locality of the entity.
    :ivar L: Alias for :py:attr:`localityName`.

    :ivar organizationName: The organization name of the entity.
    :ivar O: Alias for :py:attr:`organizationName`.

    :ivar organizationalUnitName: The organizational unit of the entity.
    :ivar OU: Alias for :py:attr:`organizationalUnitName`

    :ivar commonName: The common name of the entity.
    :ivar CN: Alias for :py:attr:`commonName`.

    :ivar emailAddress: The e-mail address of the entity.
    r   r?   r\   c                    t          j        |j                  }t          j        |t           j                  | _        dS )z
        Create a new X509Name, copying the given X509Name instance.

        :param name: The name to copy.
        :type name: :py:class:`X509Name`
        N)rF   X509_NAME_dupr   rK   rQ   X509_NAME_freer   s     r<   r   zX509Name.__init__j  s0     !$*--'$(;<<


r;   r   valuer	   c           	        |                     d          r"t                                          ||          S t          |          t          ur&t          dt          |          j        dd          t          j        t          |                    }|t          j
        k    r/	 t                       n# t          $ r Y nw xY wt          d          t          t          j        | j                            D ]z}t          j        | j        |          }t          j        |          }t          j        |          }||k    r0t          j        | j        |          }t          j        |            n{t-          |t                    r|                    d          }t          j        | j        |t          j        |ddd          }|st                       d S d S )	N_z$attribute name must be string, not 'z.200'No such attributeutf-8r   )
startswithr   __setattr__r   r   r_   r6   rF   OBJ_txt2nid_byte_string	NID_undefr   r   AttributeErrorrangeX509_NAME_entry_countr   X509_NAME_get_entryX509_NAME_ENTRY_get_objectOBJ_obj2nidX509_NAME_delete_entryX509_NAME_ENTRY_freer^   encodeX509_NAME_add_entry_by_NIDMBSTRING_UTF8)
r~   r   r
  r   ientent_objent_nid
add_resultr   s
            r<   r  zX509Name.__setattr__t  s   ??3 	477&&tU333 ::S  1KK(01 1 1  
 |D1122$.  $&&&&    !4555 t1$*==>> 	 	A*4:q99C5c::G&w//Gg~~1$*a@@)#... 
 eS!! 	*LL))E4JT/B
 

  	# """""	# 	#s   'B6 6
CC
str | Nonec                   t          j        t          |                    }|t           j        k    r/	 t	                       n# t
          $ r Y nw xY wt          d          t          j        | j        |d          }|dk    rdS t          j	        | j        |          }t          j
        |          }t          j        d          }t          j        ||          }t          |dk               	 t          j        |d         |          dd                             d          }t          j        |d                    n# t          j        |d                    w xY w|S )a
  
        Find attribute. An X509Name object has the following attributes:
        countryName (alias C), stateOrProvince (alias ST), locality (alias L),
        organization (alias O), organizationalUnit (alias OU), commonName
        (alias CN) and more...
        r  r  Nunsigned char**r   r  )rF   r  r  r  r   r   r  X509_NAME_get_index_by_NIDr   r  X509_NAME_ENTRY_get_datarK   rL   ASN1_STRING_to_UTF8rO   r=   r   OPENSSL_free)	r~   r   r   entry_indexentryrR   rW   data_lengthr   s	            r<   __getattr__zX509Name.__getattr__  s^    |D1122$.  $&&&&    !45555dj#rJJ"4([AA,U33!233.}dCCq()))	0[q!1;??BII F
 mA.////DmA.////s   A 
AA/6E   Er   r   c                    t          |t                    st          S t          j        | j        |j                  dk    S Nr   r^   r"   r   rF   X509_NAME_cmpr   r~   r   s     r<   __eq__zX509Name.__eq__  s6    %** 	"!!!$*ek::a??r;   c                    t          |t                    st          S t          j        | j        |j                  dk     S r2  r3  r5  s     r<   __lt__zX509Name.__lt__  s6    %** 	"!!!$*ek::Q>>r;   c                *   t          j        dd          }t          j        | j        |t          |                    }t          |t           j        k               d                    t          j	        |          
                    d                    S )z6
        String representation of an X509Name
        rA   i   z<X509Name object '{}'>r  )rK   rL   rF   X509_NAME_oneliner   rN   rO   rP   formatrp   r   )r~   rW   format_results      r<   r   zX509Name.__repr__  s     3//.Js='9'9
 
 	2333'..K&&--g66
 
 	
r;   r2   c                4    t          j        | j                  S )a&  
        Return an integer representation of the first four bytes of the
        MD5 digest of the DER representation of the name.

        This is the Python equivalent of OpenSSL's ``X509_NAME_hash``.

        :return: The (integer) hash of this name.
        :rtype: :py:class:`int`
        )rF   X509_NAME_hashr   r}   s    r<   hashzX509Name.hash  s     "4:...r;   rT   c                   t          j        d          }t          j        | j        |          }t          |dk               t          j        |d         |          dd         }t          j        |d                    |S )z
        Return the DER encoding of this name.

        :return: The DER encoded form of this name.
        :rtype: :py:class:`bytes`
        r(  r   N)rK   rL   rF   i2d_X509_NAMEr   rO   r=   r,  )r~   rW   encode_resultrw   s       r<   r   zX509Name.der  sv     !233*4:}EE*+++M!$4mDDQQQG-*+++r;   list[tuple[bytes, bytes]]c                   g }t          t          j        | j                            D ]}t          j        | j        |          }t          j        |          }t          j        |          }t          j        |          }t          j        |          }t          j
        t          j        |          t          j        |                    dd         }|                    t          j        |          |f           |S )z
        Returns the components of this name, as a sequence of 2-tuples.

        :return: The components of this name.
        :rtype: :py:class:`list` of ``name, value`` tuples.
        N)r  rF   r  r   r  r  r*  r  r   rK   r=   rq   rm   r   rp   )	r~   r   r!  r"  fnamefvalr   r   r
  s	            r<   get_componentszX509Name.get_components  s     t1$*==>> 	6 	6A*4:q99C3C88E055D"5))C?3''D K*400$2I$2O2O aaE MM4;t,,e45555r;   r   )r   r   r
  r	   r?   r\   )r   r   r?   r&  r   r   r   r?   rT   )r?   rC  )r6   r7   r8   r9   r   r  r0  r6  r8  r   r?  r   rG  r   r  s   @r<   r"   r"   P  s         0= = = =%# %# %# %# %# %#N& & & &P@ @ @ @? ? ? ?
 
 
 

/ 
/ 
/ 
/          r;   r"   c                      e Zd ZU dZ	 	 dddZedd            Zej        dej	        dej
        diZded<   ddZddZddZd dZd dZdS )!r!   zu
    An X.509 v3 certificate extension.

    .. deprecated:: 23.3.0
       Use cryptography's X509 APIs instead.
    N	type_namerT   criticalr   r
  subjectX509 | Noneissuerr?   r\   c                t   t          j        d          }t          j        |t           j        t           j        t           j        t           j        d           t          j        |           |0t          |t                    st          d          |j	        |_
        |0t          |t                    st          d          |j	        |_        |rd|z   }t          j        t           j        |||          }|t           j        k    rt                       t          j        |t          j                  | _        dS )a  
        Initializes an X509 extension.

        :param type_name: The name of the type of extension_ to create.
        :type type_name: :py:data:`bytes`

        :param bool critical: A flag indicating whether this is a critical
            extension.

        :param value: The OpenSSL textual representation of the extension's
            value.
        :type value: :py:data:`bytes`

        :param subject: Optional X509 certificate to use as subject.
        :type subject: :py:class:`X509`

        :param issuer: Optional X509 certificate to use as issuer.
        :type issuer: :py:class:`X509`

        .. _extension: https://www.openssl.org/docs/manmaster/man5/
            x509v3_config.html#STANDARD-EXTENSIONS
        zX509V3_CTX*r   Nzissuer must be an X509 instancez subject must be an X509 instances	   critical,)rK   rL   rF   X509V3_set_ctxrP   X509V3_set_ctx_nodbr^   r   r_   _x509issuer_certsubject_certX509V3_EXT_nconfr   rQ   X509_EXTENSION_free
_extension)r~   rJ  rK  r
  rL  rN  ctx	extensions           r<   r   zX509Extension.__init__  s   < h}%%
 	CDIty$)QOOO 	 %%% fd++ C ABBB$lCOgt,, D BCCC&}C 	) !5(E)$)S)UKK		!! """')T-EFFr;   r	   c                X    t          j        t          j        | j                            S rE   )rF   r  X509_EXTENSION_get_objectrW  r}   s    r<   r   zX509Extension._nid`  s'    *4?;;
 
 	
r;   emailDNSURIztyping.ClassVar[dict[int, str]]	_prefixesr   c                    t          j        dt          j        | j                            }t          j        |t          j                  }g }t          t          j        |                    D ]}t          j	        ||          }	 | j
        |j                 }t          j        |j        j        j        |j        j        j                  d d                              d          }|                    |dz   |z              # t&          $ r[ t)                      }t          j        ||           |                    t-          |                              d                     Y w xY wd                    |          S )NzGENERAL_NAMES*r  :z, )rK   rl   rF   X509V3_EXT_d2irW  rQ   GENERAL_NAMES_freer  sk_GENERAL_NAME_numsk_GENERAL_NAME_valuer_  r   r=   dia5rR   lengthr   r   KeyErrorrS   GENERAL_NAME_printrY   join)r~   namespartsr!  r   labelr
  rB   s           r<   _subjectAltNameStringz#X509Extension._subjectAltNameStringl  s`   	d1$/BB
 
 t677t/6677 	2 	2A-eQ77D
2ty1 DFJOTVZ5FGGAA&//  US[501111  B B B"nn'T222^C0077@@AAAAAB yys   DA"E('E(c                   t           j        | j        k    r|                                 S t	                      }t          j        || j        dd          }t          |dk               t          |          	                    d          S )zF
        :return: a nice text representation of the extension
        r   r  )
rF   NID_subject_alt_namer   ro  rS   X509V3_EXT_printrW  rO   rY   r   )r~   rB   print_results      r<   __str__zX509Extension.__str__  sv     $	11--///nn,S$/1aHH)***c""))'222r;   c                4    t          j        | j                  S )zk
        Returns the critical field of this X.509 extension.

        :return: The critical field.
        )rF   X509_EXTENSION_get_criticalrW  r}   s    r<   get_criticalzX509Extension.get_critical  s     /@@@r;   c                    t          j        | j                  }t          j        |          }t          j        |          }|t
          j        k    rt          j        |          S dS )z
        Returns the short type name of this X.509 extension.

        The result is a byte string such as :py:const:`b"basicConstraints"`.

        :return: The short type name.
        :rtype: :py:data:`bytes`

        .. versionadded:: 0.12
        s   UNDEF)rF   r[  rW  r  r   rK   rP   rp   )r~   objr   bufs       r<   get_short_namezX509Extension.get_short_name  sY     ,T_==s## oc""$);s###8r;   c                    t          j        | j                  }t          j        d|          }t          j        |          }t          j        |          }t          j        ||          dd         S )z
        Returns the data of the X509 extension, encoded as ASN.1.

        :return: The ASN.1 encoded data of this X509 extension.
        :rtype: :py:data:`bytes`

        .. versionadded:: 0.12
        rk   N)rF   X509_EXTENSION_get_datarW  rK   rl   rq   rm   r=   )r~   octet_resultrw   char_resultresult_lengths        r<   get_datazX509Extension.get_data  sb     3DODD	.,??0??/>>{;66qqq99r;   NN)rJ  rT   rK  r   r
  rT   rL  rM  rN  rM  r?   r\   r   r   r   rH  )r6   r7   r8   r9   r   propertyr   rF   	GEN_EMAILGEN_DNSGEN_URIr_  __annotations__ro  rt  rw  r{  r  r:   r;   r<   r!   r!     s           $"CG CG CG CG CGJ 
 
 
 X
 	ee2I           ,3 3 3 3A A A A   ,: : : : : :r;   r!   zZX509Extension support in pyOpenSSL is deprecated. You should use the APIs in cryptography.c                      e Zd ZdZddZddZed d            Zd!dZd"dZ	d#dZ
d$dZd%dZd&dZd'dZd(dZd)dZdS )*r#   z
    An X.509 certificate signing requests.

    .. deprecated:: 24.2.0
       Use `cryptography.x509.CertificateSigningRequest` instead.
    r?   r\   c                    t          j                    }t          j        |t           j                  | _        |                     d           d S r2  )rF   X509_REQ_newrK   rQ   X509_REQ_free_reqset_version)r~   reqs     r<   r   zX509Req.__init__  s@    !!GC!344	r;   x509.CertificateSigningRequestc                N    ddl m} t          t          |           } ||          S )z
        Export as a ``cryptography`` certificate signing request.

        :rtype: ``cryptography.x509.CertificateSigningRequest``

        .. versionadded:: 17.1.0
        r   )load_der_x509_csr)cryptography.x509r  "_dump_certificate_request_internalr   )r~   r  r   s      r<   to_cryptographyzX509Req.to_cryptography  s6     	8777770EE  %%%r;   
crypto_reqc                    t          |t          j                  st          d          ddlm} |                    |j                  }t          t          |          S )a  
        Construct based on a ``cryptography`` *crypto_req*.

        :param crypto_req: A ``cryptography`` X.509 certificate signing request
        :type crypto_req: ``cryptography.x509.CertificateSigningRequest``

        :rtype: X509Req

        .. versionadded:: 17.1.0
        z%Must be a certificate signing requestr   r   )
r^   r   CertificateSigningRequestr_   r   r   r   r   "_load_certificate_request_internalr   )r   r  r   r   s       r<   from_cryptographyzX509Req.from_cryptography  s`     *d&DEE 	ECDDDIIIIII%%hl331-EEEr;   r   r    c                j    t          j        | j        |j                  }t	          |dk               dS )z
        Set the public key of the certificate signing request.

        :param pkey: The public key to use.
        :type pkey: :py:class:`PKey`

        :return: ``None``
        r   N)rF   X509_REQ_set_pubkeyr  r   rO   r~   r   rb   s      r<   
set_pubkeyzX509Req.set_pubkey  s2     -diDD

a(((((r;   c                $   t                               t                     }t          j        | j                  |_        t          |j        t          j        k               t          j	        |j        t          j
                  |_        d|_        |S )z
        Get the public key of the certificate signing request.

        :return: The public key.
        :rtype: :py:class:`PKey`
        T)r    __new__rF   X509_REQ_get_pubkeyr  r   rO   rK   rP   rQ   r   r   r   s     r<   
get_pubkeyzX509Req.get_pubkey  se     ||D!!-di88

di/000WTZ);<<
 r;   versionr2   c                    t          |t                    st          d          |dk    rt          d          t	          j        | j        |          }t          |dk               dS )z
        Set the version subfield (RFC 2986, section 4.1) of the certificate
        request.

        :param int version: The version number.
        :return: ``None``
        zversion must be an intr   z9Invalid version. The only valid version for X509Req is 0.r   N)r^   r2   r_   ra   rF   X509_REQ_set_versionr  rO   )r~   r  rb   s      r<   r  zX509Req.set_version  sq     '3'' 	64555a<<K   .ty'BB

a(((((r;   c                4    t          j        | j                  S )z
        Get the version subfield (RFC 2459, section 4.1.2.1) of the certificate
        request.

        :return: The value of the version subfield.
        :rtype: :py:class:`int`
        )rF   X509_REQ_get_versionr  r}   s    r<   get_versionzX509Req.get_version'  s     (333r;   r"   c                    t                               t                     }t          j        | j                  |_        t          |j        t          j        k               | |_	        |S )a  
        Return the subject of this certificate signing request.

        This creates a new :class:`X509Name` that wraps the underlying subject
        name field on the certificate signing request. Modifying it will modify
        the underlying signing request, and will have the effect of modifying
        any other :class:`X509Name` that refers to this subject.

        :return: The subject of this certificate signing request.
        :rtype: :class:`X509Name`
        )
r"   r  rF   X509_REQ_get_subject_namer  r   rO   rK   rP   _ownerr   s     r<   get_subjectzX509Req.get_subject1  sP     ))3DI>>

di/000 r;   
extensions Iterable[_X509ExtensionInternal]c                   t          j        dt          d           t          j                    }t          |t          j        k               t          j        |t          j	                  }|D ]@}t          |t                    st          d          t          j        ||j                   At          j        | j        |          }t          |dk               dS )z
        Add extensions to the certificate signing request.

        :param extensions: The X.509 extensions to add.
        :type extensions: iterable of :py:class:`X509Extension`
        :return: ``None``
        This API is deprecated and will be removed in a future version of pyOpenSSL. You should use pyca/cryptography's X.509 APIs instead.   
stacklevel+One of the elements is not an X509Extensionr   N)warningswarnDeprecationWarningrF   sk_X509_EXTENSION_new_nullrO   rK   rP   rQ   sk_X509_EXTENSION_freer^   _X509ExtensionInternalra   sk_X509_EXTENSION_pushrW  X509_REQ_add_extensionsr  )r~   r  stackextr%  s        r<   add_extensionszX509Req.add_extensionsG  s     	& 	
 	
 	
 	
 /11*+++t:;; 	? 	?Cc#9:: P !NOOO 's~>>>>1$)UCC

a(((((r;   list[_X509ExtensionInternal]c                   t          j        dt          d           g }t          j        | j                  }t          j        |d           }t          t          j	        |                    D ]}t                              t                    }t          j        t          j        ||                    }t          j        |t          j                  |_        |                    |           |S )z
        Get X.509 extensions in the certificate signing request.

        :return: The X.509 extensions in this request.
        :rtype: :py:class:`list` of :py:class:`X509Extension` objects.

        .. versionadded:: 0.15
        r  r  r  c                f    t          j        | t          j        t           j        d                    S )NrV  )rF   sk_X509_EXTENSION_pop_freerK   	addressof_original_lib)xs    r<   <lambda>z(X509Req.get_extensions.<locals>.<lambda>  s)    d5t13HII  r;   )r  r  r  rF   X509_REQ_get_extensionsr  rK   rQ   r  sk_X509_EXTENSION_numr  r  X509_EXTENSION_dupsk_X509_EXTENSION_valuerV  rW  r   )r~   extsnative_exts_objr!  r  rY  s         r<   get_extensionszX509Req.get_extensionsj  s     	& 	
 	
 	
 	
 6tyAA' 
 
 t1/BBCC 	 	A(001GHHC/,_a@@ I "WY0HIICNKKr;   digestr   c                D   |j         rt          d          |j        st          d          t          j        t          |                    }|t          j        k    rt          d          t          j        | j	        |j
        |          }t          |dk               dS )aa  
        Sign the certificate signing request with this key and digest type.

        :param pkey: The key pair to sign with.
        :type pkey: :py:class:`PKey`
        :param digest: The name of the message digest to use for the signature,
            e.g. :py:data:`"sha256"`.
        :type digest: :py:class:`str`
        :return: ``None``
        zKey has only public partKey is uninitializedNo such digest methodr   N)r   ra   r   rF   EVP_get_digestbynamer  rK   rP   X509_REQ_signr  r   rO   )r~   r   r  
digest_objsign_results        r<   signzX509Req.sign  s      	97888  	53444.|F/C/CDD
""4555(DJ
KKa(((((r;   r   c                    t          |t                    st          d          t          j        | j        |j                  }|dk    rt                       |S )a@  
        Verifies the signature on this certificate signing request.

        :param PKey key: A public key.

        :return: ``True`` if the signature is correct.
        :rtype: bool

        :raises OpenSSL.crypto.Error: If the signature is invalid or there is a
            problem verifying the signature.
        pkey must be a PKey instancer   )r^   r    r_   rF   X509_REQ_verifyr  r   r   )r~   r   r   s      r<   verifyzX509Req.verify  sU     $%% 	<:;;;%di<<Q;; """r;   Nr   )r?   r  )r  r  r?   r#   r   r    r?   r\   r?   r    r  r2   r?   r\   r   r?   r"   r  r  r?   r\   )r?   r  r   r    r  r   r?   r\   )r   r    r?   r   )r6   r7   r8   r9   r   r  r   r  r  r  r  r  r  r  r  r  r  r:   r;   r<   r#   r#     s            & & & & F F F [F*
) 
) 
) 
)   ) ) ) )"4 4 4 4   ,!) !) !) !)F$ $ $ $L) ) ) )0     r;   r#   zPCSR support in pyOpenSSL is deprecated. You should use the APIs in cryptography.c                  2   e Zd ZdZd@dZedAd            ZdBd	ZedCd            ZdDdZ	dEdZ
dFdZdGdZdHdZdIdZdJdZdIdZdKdZdEdZdLd ZdLd!ZdMd#ZdNd&ZdOd'ZdPd*ZdQd+ZdOd,ZdQd-ZdRd/ZdSd1ZdTd2ZdUd4ZdTd5Z dVd7Z!dEd8Z"dWd;Z#dXd>Z$d?S )Yr   z
    An X.509 certificate.
    r?   r\   c                    t          j                    }t          |t          j        k               t          j        |t           j                  | _        t                      | _	        t                      | _
        d S rE   )rF   X509_newrO   rK   rP   rQ   	X509_freerR  rz   _issuer_invalidator_subject_invalidator)r~   r   s     r<   r   zX509.__init__  sY    }	)***WT4>22
#7#9#9 $8$:$:!!!r;   r   r	   c                    |                      |           }t          j        |t          j                  |_        t                      |_        t                      |_        |S rE   )	r  rK   rQ   rF   r  rR  rz   r  r  )r   r   certs      r<   _from_raw_x509_ptrzX509._from_raw_x509_ptr  sI    {{3WT4>22
#7#9#9 $8$:$:!r;   x509.Certificatec                N    ddl m} t          t          |           } ||          S )z
        Export as a ``cryptography`` certificate.

        :rtype: ``cryptography.x509.Certificate``

        .. versionadded:: 17.1.0
        r   )load_der_x509_certificate)r  r  r(   r   )r~   r  r   s      r<   r  zX509.to_cryptography  s7     	@?????}d33((---r;   crypto_certc                    t          |t          j                  st          d          ddlm} |                    |j                  }t          t          |          S )z
        Construct based on a ``cryptography`` *crypto_cert*.

        :param crypto_key: A ``cryptography`` X.509 certificate.
        :type crypto_key: ``cryptography.x509.Certificate``

        :rtype: X509

        .. versionadded:: 17.1.0
        zMust be a certificater   r  )
r^   r   Certificater_   r   r   r   r   r.   r   )r   r  r   r   s       r<   r  zX509.from_cryptography  s_     +t'788 	53444IIIIII&&x|44s333r;   r  r2   c                    t          |t                    st          d          t          t	          j        | j        |          dk               dS )a	  
        Set the version number of the certificate. Note that the
        version value is zero-based, eg. a value of 0 is V1.

        :param version: The version number of the certificate.
        :type version: :py:class:`int`

        :return: ``None``
        zversion must be an integerr   N)r^   r2   r_   rO   rF   X509_set_versionrR  )r~   r  s     r<   r  zX509.set_version  sM     '3'' 	:8999-dj'BBaGHHHHHr;   c                4    t          j        | j                  S )z
        Return the version number of the certificate.

        :return: The version number of the certificate.
        :rtype: :py:class:`int`
        )rF   X509_get_versionrR  r}   s    r<   r  zX509.get_version  s     $TZ000r;   r    c                &   t                               t                     }t          j        | j                  |_        |j        t          j        k    rt                       t          j	        |j        t          j
                  |_        d|_        |S )z{
        Get the public key of the certificate.

        :return: The public key.
        :rtype: :py:class:`PKey`
        T)r    r  rF   X509_get_pubkeyrR  r   rK   rP   r   rQ   r   r   r   s     r<   r  zX509.get_pubkey  si     ||D!!)$*55
:"" """WTZ);<<
 r;   r   c                    t          |t                    st          d          t          j        | j        |j                  }t          |dk               dS )z
        Set the public key of the certificate.

        :param pkey: The public key.
        :type pkey: :py:class:`PKey`

        :return: :py:data:`None`
        r  r   N)r^   r    r_   rF   X509_set_pubkeyrR  r   rO   r  s      r<   r  zX509.set_pubkey)  sS     $%% 	<:;;;)$*djAA

a(((((r;   r  r   c                   t          |t                    st          d          |j        rt	          d          |j        st	          d          t          j        t          |                    }|t          j
        k    rt	          d          t          j        | j        |j        |          }t          |dk               dS )a  
        Sign the certificate with this key and digest type.

        :param pkey: The key to sign with.
        :type pkey: :py:class:`PKey`

        :param digest: The name of the message digest to use.
        :type digest: :py:class:`str`

        :return: :py:data:`None`
        r  zKey only has public partr  r  r   N)r^   r    r_   r   ra   r   rF   r  r  rK   rP   	X509_signrR  r   rO   )r~   r   r  evp_mdr  s        r<   r  z	X509.sign8  s     $%% 	<:;;; 	97888  	53444*<+?+?@@TY4555nTZVDDa(((((r;   rT   c                p   t          j        | j                  }t          j        d          }t          j        |t          j        t          j        |           t          j        |d                   }|t           j        k    rt          d          t          j
        t          j        |                    S )z
        Return the signature algorithm used in the certificate.

        :return: The name of the algorithm.
        :rtype: :py:class:`bytes`

        :raises ValueError: If the signature algorithm is undefined.

        .. versionadded:: 0.13
        zASN1_OBJECT **r   zUndefined signature algorithm)rF   X509_get0_tbs_sigalgrR  rK   rL   X509_ALGOR_get0rP   r  r  ra   rp   
OBJ_nid2ln)r~   sig_algalgr   s       r<   get_signature_algorithmzX509.get_signature_algorithmT  s     +DJ77h'((S$)TY@@@s1v&&$.  <==={4?3//000r;   digest_namec                   t          j        t          |                    }|t          j        k    rt          d          t          j        dt           j                  }t          j        dd          }t          |          |d<   t          j	        | j
        |||          }t          |dk               d                    d t          j        ||d                   D                       S )a5  
        Return the digest of the X509 object.

        :param digest_name: The name of the digest algorithm to use.
        :type digest_name: :py:class:`str`

        :return: The digest of the object, formatted as
            :py:const:`b":"`-delimited hex pairs.
        :rtype: :py:class:`bytes`
        r  zunsigned char[]zunsigned int[]r   r      :c                P    g | ]#}t          |                                          $S r:   )r   upper)r   chs     r<   
<listcomp>zX509.digest.<locals>.<listcomp>  s:        "##%%  r;   )rF   r  r  rK   rP   ra   rL   EVP_MAX_MD_SIZErN   X509_digestrR  rO   rk  r=   )r~   r  r  rW   r  digest_results         r<   r  zX509.digestg  s     *<+D+DEETY4555!2D4HII!1155}--a(J}
 
 	*+++yy +m]15EFF  
 
 	
r;   c                4    t          j        | j                  S )z
        Return the hash of the X509 subject.

        :return: The hash of the subject.
        :rtype: :py:class:`bytes`
        )rF   X509_subject_name_hashrR  r}   s    r<   subject_name_hashzX509.subject_name_hash  s     *4:666r;   serialc                   t          |t                    st          d          t          |          dd         }|                    d          }t          j        d          }t          j        ||          }t          |t
          j
        k               t          j        |d         t
          j
                  }t          j        |d                    t          |t
          j
        k               t          j        |t          j                  }t          j        | j        |          }t          |dk               dS )z
        Set the serial number of the certificate.

        :param serial: The new serial number.
        :type serial: :py:class:`int`

        :return: :py:data`None`
        zserial must be an integerr  Nr   zBIGNUM**r   r   )r^   r2   r_   hexr  rK   rL   rF   	BN_hex2bnrO   rP   BN_to_ASN1_INTEGERr   rQ   ASN1_INTEGER_freeX509_set_serialNumberrR  )r~   r  
hex_serialhex_serial_bytesbignum_serialr   asn1_serialrb   s           r<   set_serial_numberzX509.set_serial_number  s    &#&& 	97888[[_
%,,W55,, /?@@$)+,,,-mA.>	JJ]1%&&&ty0111gk4+ABB/
KHH

a(((((r;   c                   t          j        | j                  }t          j        |t          j                  }	 t          j        |          }	 t	          j        |          }t          |d          }|t          j	        |           t          j
        |           S # t          j	        |           w xY w# t          j
        |           w xY w)zx
        Return the serial number of this certificate.

        :return: The serial number.
        :rtype: int
           )rF   X509_get_serialNumberrR  ASN1_INTEGER_to_BNrK   rP   	BN_bn2hexrp   r2   r,  r   )r~   r  r  r  hexstring_serialr  s         r<   get_serial_numberzX509.get_serial_number  s     0<</TYGG		(66J.#';z#:#: -r22!*---L'''' !*----L''''s#   B6 %B 4B6 B33B6 6Camountc                    t          |t                    st          d          t          j        | j                  }t          j        ||           dS )z
        Adjust the time stamp on which the certificate stops being valid.

        :param int amount: The number of seconds by which to adjust the
            timestamp.
        :return: ``None``
        amount must be an integerN)r^   r2   r_   rF   X509_getm_notAfterrR  X509_gmtime_adj)r~   r#  notAfters      r<   gmtime_adj_notAfterzX509.gmtime_adj_notAfter  sP     &#&& 	97888*4:66Xv.....r;   c                    t          |t                    st          d          t          j        | j                  }t          j        ||           dS )z
        Adjust the timestamp on which the certificate starts being valid.

        :param amount: The number of seconds by which to adjust the timestamp.
        :return: ``None``
        r%  N)r^   r2   r_   rF   X509_getm_notBeforerR  r'  )r~   r#  	notBefores      r<   gmtime_adj_notBeforezX509.gmtime_adj_notBefore  sP     &#&& 	97888,TZ88	Y/////r;   r   c                J   |                                  }|t          d          |                    d          }t          j                            |d          }t          j        j        }t          j                            |                              d          }||k     S )z
        Check whether the certificate has expired.

        :return: ``True`` if the certificate has expired, ``False`` otherwise.
        :rtype: bool
        NzUnable to determine notAfterr  z%Y%m%d%H%M%SZ)tzinfo)	get_notAfterra   r   datetimestrptimetimezoneutcnowreplace)r~   
time_bytestime_string	not_afterUTCutcnows         r<   has_expiredzX509.has_expired  s     &&((
;<<< ''00%..{OLL	#"&&s++3343@@6!!r;   whichr>   c                <    t           || j                            S rE   )rx   rR  )r~   r=  s     r<   _get_boundary_timezX509._get_boundary_time  s    eeDJ//000r;   c                @    |                      t          j                  S )a
  
        Get the timestamp at which the certificate starts being valid.

        The timestamp is formatted as an ASN.1 TIME::

            YYYYMMDDhhmmssZ

        :return: A timestamp string, or ``None`` if there is none.
        :rtype: bytes or NoneType
        )r?  rF   r+  r}   s    r<   get_notBeforezX509.get_notBefore  s     &&t'?@@@r;   Callable[..., Any]r[   c                >    t           || j                  |          S rE   )rc   rR  )r~   r=  r[   s      r<   _set_boundary_timezX509._set_boundary_time  s      eeDJ//666r;   c                B    |                      t          j        |          S )z
        Set the timestamp at which the certificate starts being valid.

        The timestamp is formatted as an ASN.1 TIME::

            YYYYMMDDhhmmssZ

        :param bytes when: A timestamp string.
        :return: ``None``
        )rD  rF   r+  r~   r[   s     r<   set_notBeforezX509.set_notBefore   s     &&t'?FFFr;   c                @    |                      t          j                  S )a	  
        Get the timestamp at which the certificate stops being valid.

        The timestamp is formatted as an ASN.1 TIME::

            YYYYMMDDhhmmssZ

        :return: A timestamp string, or ``None`` if there is none.
        :rtype: bytes or NoneType
        )r?  rF   r&  r}   s    r<   r0  zX509.get_notAfter  s     &&t'>???r;   c                B    |                      t          j        |          S )z
        Set the timestamp at which the certificate stops being valid.

        The timestamp is formatted as an ASN.1 TIME::

            YYYYMMDDhhmmssZ

        :param bytes when: A timestamp string.
        :return: ``None``
        )rD  rF   r&  rF  s     r<   set_notAfterzX509.set_notAfter  s     &&t'>EEEr;   r"   c                    t                               t                     } || j                  |_        t	          |j        t
          j        k               | |_        |S rE   )r"   r  rR  r   rO   rK   rP   r  )r~   r=  r   s      r<   	_get_namezX509._get_name'  sM    ))U4:&&

di/000 r;   r   c                    t          |t                    st          d           || j        |j                  }t          |dk               d S )Nzname must be an X509Namer   )r^   r"   r_   rR  r   rO   )r~   r=  r   rb   s       r<   	_set_namezX509._set_name2  sP    $)) 	86777U4:tz22

a(((((r;   c                x    |                      t          j                  }| j                            |           |S )a  
        Return the issuer of this certificate.

        This creates a new :class:`X509Name` that wraps the underlying issuer
        name field on the certificate. Modifying it will modify the underlying
        certificate, and will have the effect of modifying any other
        :class:`X509Name` that refers to this issuer.

        :return: The issuer of this certificate.
        :rtype: :class:`X509Name`
        )rL  rF   X509_get_issuer_namer  r   r   s     r<   
get_issuerzX509.get_issuer8  s4     ~~d788 $$T***r;   rN  c                x    |                      t          j        |           | j                                         dS )z
        Set the issuer of this certificate.

        :param issuer: The issuer.
        :type issuer: :py:class:`X509Name`

        :return: ``None``
        N)rN  rF   X509_set_issuer_namer  r   )r~   rN  s     r<   
set_issuerzX509.set_issuerH  s6     	t0&999 &&(((((r;   c                x    |                      t          j                  }| j                            |           |S )a  
        Return the subject of this certificate.

        This creates a new :class:`X509Name` that wraps the underlying subject
        name field on the certificate. Modifying it will modify the underlying
        certificate, and will have the effect of modifying any other
        :class:`X509Name` that refers to this subject.

        :return: The subject of this certificate.
        :rtype: :class:`X509Name`
        )rL  rF   X509_get_subject_namer  r   r   s     r<   r  zX509.get_subjectT  s4     ~~d899!%%d+++r;   rL  c                x    |                      t          j        |           | j                                         dS )z
        Set the subject of this certificate.

        :param subject: The subject.
        :type subject: :py:class:`X509Name`

        :return: ``None``
        N)rN  rF   X509_set_subject_namer  r   )r~   rL  s     r<   set_subjectzX509.set_subjectd  s6     	t17;;;!'')))))r;   c                4    t          j        | j                  S )z
        Get the number of extensions on this certificate.

        :return: The number of extensions.
        :rtype: :py:class:`int`

        .. versionadded:: 0.12
        )rF   X509_get_ext_countrR  r}   s    r<   get_extension_countzX509.get_extension_countp  s     &tz222r;   r  r  c                    t          j        dt          d           |D ]Y}t          |t                    st          d          t          j        | j        |j	        d          }t          |dk               ZdS )z
        Add extensions to the certificate.

        :param extensions: The extensions to add.
        :type extensions: An iterable of :py:class:`X509Extension` objects.
        :return: ``None``
        r  r  r  r  r  r   N)r  r  r  r^   r  ra   rF   X509_add_extrR  rW  rO   )r~   r  r  r%  s       r<   r  zX509.add_extensions{  s     	& 	
 	
 	
 	
  	- 	-Cc#9:: P !NOOO*4:s~rJJJJ!O,,,,	- 	-r;   indexr  c                |   t          j        dt          d           t                              t                    }t          j        | j        |          |_        |j        t          j
        k    rt          d          t          j        |j                  }t          j        |t
          j                  |_        |S )a  
        Get a specific extension of the certificate by index.

        Extensions on a certificate are kept in order. The index
        parameter selects which extension will be returned.

        :param int index: The index of the extension to retrieve.
        :return: The extension at the specified index.
        :rtype: :py:class:`X509Extension`
        :raises IndexError: If the extension index was out of bounds.

        .. versionadded:: 0.12
        r  r  r  zextension index out of bounds)r  r  r  r  r  rF   X509_get_extrR  rW  rK   rP   
IndexErrorr  rQ   rV  )r~   r_  r  rY  s       r<   get_extensionzX509.get_extension  s     	& 	
 	
 	
 	
 %,,-CDD*4:u==>TY&&<===+CN;;	D,DEE
r;   Nr   )r   r	   r?   r   )r?   r  )r  r  r?   r   r  r   r  r  r  rH  )r  r   r?   rT   )r  r2   r?   r\   )r#  r2   r?   r\   r   )r=  r	   r?   r>   )r?   r>   )r=  rB  r[   rT   r?   r\   )r[   rT   r?   r\   )r=  r	   r?   r"   )r=  r	   r   r"   r?   r\   r  )rN  r"   r?   r\   )rL  r"   r?   r\   r  )r_  r2   r?   r  )%r6   r7   r8   r9   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r"  r)  r-  r<  r?  rA  rD  rG  r0  rJ  rL  rN  rQ  rT  r  rY  r\  r  rc  r:   r;   r<   r   r     s        ; ; ; ;    [. . . . 4 4 4 [4&I I I I1 1 1 1   ) ) ) )) ) ) )81 1 1 1&
 
 
 
>7 7 7 7) ) ) )8( ( ( ((/ / / /0 0 0 0" " " ""1 1 1 1A A A A7 7 7 7
G G G G@ @ @ @F F F F	 	 	 	) ) ) )    
) 
) 
) 
)    
* 
* 
* 
*	3 	3 	3 	3- - - -6     r;   r   c                     e Zd ZU dZej        Zded<   ej        Z	ded<   ej
        Zded<   ej        Zded<   ej        Zded<   ej        Zded<   ej        Zded	<   ej        Zded
<   ej        Zded<   ej        Zded<   dS )r'   a  
    Flags for X509 verification, used to change the behavior of
    :class:`X509Store`.

    See `OpenSSL Verification Flags`_ for details.

    .. _OpenSSL Verification Flags:
        https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_flags.html
    r2   	CRL_CHECKCRL_CHECK_ALLIGNORE_CRITICALX509_STRICTALLOW_PROXY_CERTSPOLICY_CHECKEXPLICIT_POLICYINHIBIT_MAPCHECK_SS_SIGNATUREPARTIAL_CHAINN)r6   r7   r8   r9   rF   X509_V_FLAG_CRL_CHECKre  r  X509_V_FLAG_CRL_CHECK_ALLrf  X509_V_FLAG_IGNORE_CRITICALrg  X509_V_FLAG_X509_STRICTrh  X509_V_FLAG_ALLOW_PROXY_CERTSri  X509_V_FLAG_POLICY_CHECKrj  X509_V_FLAG_EXPLICIT_POLICYrk  X509_V_FLAG_INHIBIT_MAPrl  X509_V_FLAG_CHECK_SS_SIGNATURErm  X509_V_FLAG_PARTIAL_CHAINrn  r:   r;   r<   r'   r'     s           /I////7M7777;O;;;;3K3333!?????5L5555;O;;;;3K3333"AAAAA7M777777r;   r'   c                  F    e Zd ZdZddZddZdd
ZddZddZ	 dddZ	dS )r$   a  
    An X.509 store.

    An X.509 store is used to describe a context in which to verify a
    certificate. A description of a context may include a set of certificates
    to trust, a set of certificate revocation lists, verification flags and
    more.

    An X.509 store, being only a description, cannot be used by itself to
    verify a certificate. To carry out the actual verification process, see
    :class:`X509StoreContext`.
    r?   r\   c                t    t          j                    }t          j        |t           j                  | _        d S rE   )rF   X509_STORE_newrK   rQ   X509_STORE_free_storer~   stores     r<   r   zX509Store.__init__  s*    #%%geT%9::r;   r  r   c                    t          |t                    st                      t          j        | j        |j                  }t          |dk               dS )a  
        Adds a trusted certificate to this store.

        Adding a certificate with this method adds this certificate as a
        *trusted* certificate.

        :param X509 cert: The certificate to add to this store.

        :raises TypeError: If the certificate is not an :class:`X509`.

        :raises OpenSSL.crypto.Error: If OpenSSL was unhappy with your
            certificate.

        :return: ``None`` if the certificate was added successfully.
        r   N)r^   r   r_   rF   X509_STORE_add_certr}  rR  rO   )r~   r  r   s      r<   add_certzX509Store.add_cert  sN      $%% 	++&t{DJ??q!!!!!r;   crlx509.CertificateRevocationListc                   t          |t          j                  rddlm} t          |                    |j                            }t          j	        |t          j                  }t          |t          j        k               t          j        |t          j                  }nt          d          t          t          j        | j        |          dk               dS )a  
        Add a certificate revocation list to this store.

        The certificate revocation lists added to a store will only be used if
        the associated flags are configured to check certificate revocation
        lists.

        .. versionadded:: 16.1.0

        :param crl: The certificate revocation list to add to this store.
        :type crl: ``cryptography.x509.CertificateRevocationList``
        :return: ``None`` if the certificate revocation list was added
            successfully.
        r   r  z?CRL must be of type cryptography.x509.CertificateRevocationListN)r^   r   CertificateRevocationListr   r   rS   r   r   rF   d2i_X509_CRL_biorK   rP   rO   rQ   X509_CRL_freer_   X509_STORE_add_crlr}  )r~   r  r   rB   openssl_crls        r<   add_crlzX509Store.add_crl  s     c49:: 	MMMMMMs//==>>C/TY??KK494555'+t'9::CC>  
 	/SAAQFGGGGGr;   flagsr2   c                \    t          t          j        | j        |          dk               dS )a  
        Set verification flags to this store.

        Verification flags can be combined by oring them together.

        .. note::

          Setting a verification flag sometimes requires clients to add
          additional information to the store, otherwise a suitable error will
          be raised.

          For example, in setting flags to enable CRL checking a
          suitable CRL must be added to the store otherwise an error will be
          raised.

        .. versionadded:: 16.1.0

        :param int flags: The verification flags to set on this store.
            See :class:`X509StoreFlags` for available constants.
        :return: ``None`` if the verification flags were successfully set.
        r   N)rO   rF   X509_STORE_set_flagsr}  )r~   r  s     r<   	set_flagszX509Store.set_flags  s,    , 	1$+uEEJKKKKKr;   vfy_timedatetime.datetimec                2   t          j                    }t          j        |t           j                  }t          j        |t          j        |                                                     t          t          j
        | j        |          dk               dS )a  
        Set the time against which the certificates are verified.

        Normally the current time is used.

        .. note::

          For example, you can determine if a certificate was valid at a given
          time.

        .. versionadded:: 17.0.0

        :param datetime vfy_time: The verification time to set on this store.
        :return: ``None`` if the verification time was successfully set.
        r   N)rF   X509_VERIFY_PARAM_newrK   rQ   X509_VERIFY_PARAM_freeX509_VERIFY_PARAM_set_timecalendartimegm	timetuplerO   X509_STORE_set1_paramr}  )r~   r  params      r<   set_timezX509Store.set_time-  s      *,,t:;;'8?8#5#5#7#788	
 	
 	
 	24;FF!KLLLLLr;   NcafileStrOrBytesPathcapathStrOrBytesPath | Nonec                    |t           j        }nt          |          }|t           j        }nt          |          }t          j        | j        ||          }|st                       dS dS )a  
        Let X509Store know where we can find trusted certificates for the
        certificate chain.  Note that the certificates have to be in PEM
        format.

        If *capath* is passed, it must be a directory prepared using the
        ``c_rehash`` tool included with OpenSSL.  Either, but not both, of
        *cafile* or *capath* may be ``None``.

        .. note::

          Both *cafile* and *capath* may be set simultaneously.

          Call this method multiple times to add more than one location.
          For example, CA certificates, and certificate revocation list bundles
          may be passed in *cafile* in subsequent calls to this method.

        .. versionadded:: 20.0

        :param cafile: In which file we can find the certificates (``bytes`` or
                       ``unicode``).
        :param capath: In which directory we can find the certificates
                       (``bytes`` or ``unicode``).

        :return: ``None`` if the locations were set successfully.

        :raises OpenSSL.crypto.Error: If both *cafile* and *capath* is ``None``
            or the locations could not be set for any reason.

        N)rK   rP   _path_bytesrF   X509_STORE_load_locationsr}  r   )r~   r  r  load_results       r<   load_locationszX509Store.load_locationsE  s|    B >YFF ((F>YFF ((F4K
 
  	# """""	# 	#r;   r   )r  r   r?   r\   )r  r  r?   r\   )r  r2   r?   r\   )r  r  r?   r\   rE   )r  r  r  r  r?   r\   )
r6   r7   r8   r9   r   r  r  r  r  r  r:   r;   r<   r$   r$     s         ; ; ; ;" " " ",H H H H<L L L L0M M M M2 GK/# /# /# /# /# /# /#r;   r$   c                  $     e Zd ZdZd fd
Z xZS )r&   z
    An exception raised when an error occurred while verifying a certificate
    using `OpenSSL.X509StoreContext.verify_certificate`.

    :ivar certificate: The certificate which caused verificate failure.
    :type certificate: :class:`X509`
    messager   errors	list[Any]certificater   r?   r\   c                f    t                                          |           || _        || _        d S rE   )r   r   r  r  )r~   r  r  r  r   s       r<   r   zX509StoreContextError.__init__  s2     	!!!&r;   )r  r   r  r  r  r   r?   r\   )r6   r7   r8   r9   r   r   r  s   @r<   r&   r&   w  sG         ' ' ' ' ' ' ' ' ' 'r;   r&   c                  n    e Zd ZdZ	 dddZedd            Zedd            ZddZddZ	ddZ
ddZdS )r%   a9  
    An X.509 store context.

    An X.509 store context is used to carry out the actual verification process
    of a certificate in a described context. For describing such a context, see
    :class:`X509Store`.

    :param X509Store store: The certificates which will be trusted for the
        purposes of any verifications.
    :param X509 certificate: The certificate to be verified.
    :param chain: List of untrusted certificates that may be used for building
        the certificate chain. May be ``None``.
    :type chain: :class:`list` of :class:`X509`
    Nr  r$   r  r   chainSequence[X509] | Noner?   r\   c                V    || _         || _        |                     |          | _        d S rE   )r}  _cert_build_certificate_stack_chain)r~   r  r  r  s       r<   r   zX509StoreContext.__init__  s+      
33E::r;   certificatesc                
   dd}| t          |           dk    rt          j        S t          j                    }t          |t          j        k               t          j        ||          }| D ]}t          |t                    st          d          t          t          j
        |j                  dk               t          j        ||j                  dk    r't          j        |j                   t                       |S )	Nsr	   r?   r\   c                    t          t          j        |                     D ]+}t          j        | |          }t          j        |           ,t          j        |            d S rE   )r  rF   sk_X509_numsk_X509_valuer  sk_X509_free)r  r!  r  s      r<   cleanupz:X509StoreContext._build_certificate_stack.<locals>.cleanup  sb     4+A..// " "&q!,,q!!!!a     r;   r   z+One of the elements is not an X509 instance)r  r	   r?   r\   )rN   rK   rP   rF   sk_X509_new_nullrO   rQ   r^   r   r_   X509_up_refrR  sk_X509_pushr  r   )r  r  r  r  s       r<   r  z)X509StoreContext._build_certificate_stack  s    	! 	! 	! 	! 3|#4#4#9#99%''*+++w''  	' 	'DdD)) O MNNND,TZ881<=== 
33q88tz***$&&&r;   	store_ctxr	   r&   c                   t          j        t          j        t          j        |                                                   d          }t          j        |           t          j        |           |g}t          j        |           }t          j        |          }t          
                    |          }t          |||          S )z
        Convert an OpenSSL native context error failure into a Python
        exception.

        When a call to native OpenSSL X509_verify_cert fails, additional
        information about the failure can be obtained from the store context.
        r  )rK   rp   rF   X509_verify_cert_error_stringX509_STORE_CTX_get_errorr   X509_STORE_CTX_get_error_depthX509_STORE_CTX_get_current_certX509_dupr   r  r&   )r  r  r  rR  r  pycerts         r<   _exception_from_contextz(X509StoreContext._exception_from_context  s     +.-i88 
 
 &//	 	 ))44/	::
 4Y??e$$((//$Wff===r;   c                   t          j                    }t          |t          j        k               t          j        |t           j                  }t          j        || j        j        | j	        j
        | j                  }t          |dk               t          j        |          }|dk    r|                     |          |S )a3  
        Verifies the certificate and runs an X509_STORE_CTX containing the
        results.

        :raises X509StoreContextError: If an error occurred when validating a
          certificate in the context. Sets ``certificate`` attribute to
          indicate which certificate caused the error.
        r   r   )rF   X509_STORE_CTX_newrO   rK   rP   rQ   X509_STORE_CTX_freeX509_STORE_CTX_initr}  r  rR  r  X509_verify_certr  )r~   r  rg   s      r<   _verify_certificatez$X509StoreContext._verify_certificate  s     +--		TY.///GIt'?@@	&t{)4:+;T[
 
 	q!!!#I..!88..y999r;   c                    || _         dS )z
        Set the context's X.509 store.

        .. versionadded:: 0.15

        :param X509Store store: The store description which will be used for
            the purposes of any *future* verifications.
        N)r}  r~  s     r<   	set_storezX509StoreContext.set_store  s     r;   c                .    |                                   dS )a"  
        Verify a certificate in a context.

        .. versionadded:: 0.15

        :raises X509StoreContextError: If an error occurred when validating a
          certificate in the context. Sets ``certificate`` attribute to
          indicate which certificate caused the error.
        N)r  r}   s    r<   verify_certificatez#X509StoreContext.verify_certificate  s     	  """""r;   
list[X509]c                   |                                  }t          j        |          }t          |t          j        k               g }t          t          j        |                    D ]c}t          j        ||          }t          |t          j        k               t          
                    |          }|                    |           dt          j        |           |S )aR  
        Verify a certificate in a context and return the complete validated
        chain.

        :raises X509StoreContextError: If an error occurred when validating a
          certificate in the context. Sets ``certificate`` attribute to
          indicate which certificate caused the error.

        .. versionadded:: 20.0
        )r  rF   X509_STORE_CTX_get1_chainrO   rK   rP   r  r  r  r   r  r   r  )r~   r  
cert_stackr   r!  r  r  s          r<   get_verified_chainz#X509StoreContext.get_verified_chain	  s     ,,..	 3I>>

di/000t'
3344 	" 	"A%j!44DDDI-...,,T22FMM&!!!! 	*%%%r;   rE   )r  r$   r  r   r  r  r?   r\   )r  r  r?   r\   )r  r	   r?   r&   r   )r  r$   r?   r\   r   )r?   r  )r6   r7   r8   r9   r   staticmethodr  r  r  r  r  r  r:   r;   r<   r%   r%     s         & (,	; ; ; ; ;    \: > > > \>2   0	 	 	 	
# 
# 
# 
#     r;   r%   r   c                   t          |t                    r|                    d          }t          |          }| t          k    r6t          j        |t          j        t          j        t          j                  }n:| t          k    r t          j
        |t          j                  }nt          d          |t          j        k    rt                       t                              |          S )a  
    Load a certificate (X509) from the string *buffer* encoded with the
    type *type*.

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)

    :param bytes buffer: The buffer the certificate is stored in

    :return: The X509 object
    r   3type argument must be FILETYPE_PEM or FILETYPE_ASN1)r^   r   r  rS   r   rF   PEM_read_bio_X509rK   rP   r   d2i_X509_biora   r   r   r  )r   r=   rB   r   s       r<   r.   r.   &  s     &# (w''
v

C|%c49diKK			 di00NOOOty""4(((r;   r  c                h   t                      }| t          k    rt          j        ||j                  }n]| t
          k    rt          j        ||j                  }n7| t          k    rt          j        ||j        dd          }nt          d          t          |dk               t          |          S )a  
    Dump the certificate *cert* into a buffer string encoded with the type
    *type*.

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1, or
        FILETYPE_TEXT)
    :param cert: The certificate to dump
    :return: The buffer with the dumped certificate in
    r   Ctype argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXTr   )rS   r   rF   PEM_write_bio_X509rR  r   i2d_X509_bior   X509_print_exra   rO   rY   )r   r  rB   result_codes       r<   r(   r(   C  s     ..C|-c4:>>			'TZ88			(dj!Q??
 
 	

 K1$%%%#r;   r   c                   t                      }| t          k    rt          j        }n'| t          k    rt          j        }nt          d           |||j                  }|dk    rt                       t          |          S )z
    Dump a public key to a buffer.

    :param type: The file type (one of :data:`FILETYPE_PEM` or
        :data:`FILETYPE_ASN1`).
    :param PKey pkey: The public key to dump
    :return: The buffer with the dumped key in it.
    :rtype: bytes
    r  r   )
rS   r   rF   PEM_write_bio_PUBKEYr   i2d_PUBKEY_biora   r   r   rY   )r   r   rB   	write_bior  s        r<   r+   r+   _  s~     ..C|-					'		NOOO)C,,Ka#r;   cipherr&  
passphrasePassphraseCallableT | Nonec           	        t                      }t          |t                    st          d          |R|t          d          t	          j        t          |                    }|t          j        k    rt          d          nt          j        }t          | |          }| t          k    rHt	          j        ||j        |t          j        d|j        |j                  }|                                 n| t"          k    rt	          j        ||j                  }n| t&          k    rt	          j        |j                  t          j        k    rt          d          t          j        t	          j        |j                  t          j                  }t	          j        ||d          }nt          d          t5          |dk               t7          |          S )a  
    Dump the private key *pkey* into a buffer string encoded with the type
    *type*.  Optionally (if *type* is :const:`FILETYPE_PEM`) encrypting it
    using *cipher* and *passphrase*.

    :param type: The file type (one of :const:`FILETYPE_PEM`,
        :const:`FILETYPE_ASN1`, or :const:`FILETYPE_TEXT`)
    :param PKey pkey: The PKey to dump
    :param cipher: (optional) if encrypted PEM format, the cipher to use
    :param passphrase: (optional) if encrypted PEM format, this can be either
        the passphrase to use, or a callback for providing the passphrase.

    :return: The buffer with the dumped key in
    :rtype: bytes
    zpkey must be a PKeyNzDif a value is given for cipher one must also be given for passphrasezInvalid cipher namer   z-Only RSA keys are supported for FILETYPE_TEXTr  )rS   r^   r    r_   rF   EVP_get_cipherbynamer  rK   rP   ra   _PassphraseHelperr   PEM_write_bio_PrivateKeyr   callbackcallback_argsraise_if_problemr   i2d_PrivateKey_bior   r   r   rQ   r   r   	RSA_printrO   rY   )	r   r   r  r  rB   
cipher_objhelperr  r   s	            r<   r*   r*   x  s   * ..CdD!! /-...8   .|F/C/CDD
""2333 # Y
tZ00F|3JIO 
 
 	!!!!			-c4:>>			DJ''4+<<<KLLLgd,TZ88$-HHnS#q11
 
 	

 K1$%%%#r;   c                  `    e Zd Z	 	 dddZedd            Zedd            ZefddZddZ	dS )r  Fr   r2   r  r  	more_argsr   truncater?   r\   c                v    |t           k    r|t          d          || _        || _        || _        g | _        d S )Nz0only FILETYPE_PEM key format supports encryption)r   ra   _passphrase
_more_args	_truncate	_problems)r~   r   r  r  r  s        r<   r   z_PassphraseHelper.__init__  sL     <J$:B   &#!*,r;   r	   c                    | j         t          j        S t          | j         t                    st          | j                   rt          j        d| j                  S t          d          )Npem_password_cb2Last argument must be a byte string or a callable.)	r  rK   rP   r^   rT   callabler  _read_passphraser_   r}   s    r<   r  z_PassphraseHelper.callback  se    #9(%00 	HT=M4N4N 	=!2D4IJJJD  r;   c                    | j         t          j        S t          | j         t                    st          | j                   rt          j        S t          d          )Nr  )r  rK   rP   r^   rT   r  r_   r}   s    r<   r  z_PassphraseHelper.callback_args  sW    #9(%00 	HT=M4N4N 	9D  r;   exceptionTypetype[Exception]c                    | j         r6	 t          |           n# |$ r Y nw xY w| j                             d          d S r2  )r  _exception_from_error_queuepop)r~   r   s     r<   r  z"_PassphraseHelper.raise_if_problem  sd    > 	(+M::::     .$$Q'''	( 	(s    !!rz  sizerwflaguserdatac                F   	 t          | j                  r5| j        r|                     |||          }n&|                     |          }n| j        J | j        }t          |t                    st          d          t          |          |k    r!| j        r|d |         }nt          d          t          t          |                    D ]}|||dz            ||<   t          |          S # t          $ r%}| j
                            |           Y d }~dS d }~ww xY w)NzBytes expectedz+passphrase returned by callback is too longr   r   )r  r  r  r^   rT   ra   rN   r  r  	Exceptionr  r   )r~   rz  r  r  r  r   r!  es           r<   r  z"_PassphraseHelper._read_passphrase  sN   	()) *? 6!--dFHEEFF!--f55FF'333)fe,, 3 !12226{{T!!> #ETE]FF$E   3v;;'' + +AE	*Av;; 	 	 	N!!!$$$11111	s   C.C1 1
D ;DD N)FF)
r   r2   r  r  r  r   r  r   r?   r\   r   )r   r  r?   r\   )
rz  r	   r  r2   r  r	   r  r	   r?   r2   )
r6   r7   r8   r   r  r  r  r   r  r  r:   r;   r<   r  r    s        
  - - - - -     X    X AF ( ( ( ( (     r;   r  str | bytesc                >   t          |t                    r|                    d          }t          |          }| t          k    r6t          j        |t          j        t          j        t          j                  }n:| t          k    r t          j
        |t          j                  }nt          d          |t          j        k    rt                       t                              t                    }t          j        |t
          j                  |_        d|_        |S )a<  
    Load a public key from a buffer.

    :param type: The file type (one of :data:`FILETYPE_PEM`,
        :data:`FILETYPE_ASN1`).
    :param buffer: The buffer the key is stored in.
    :type buffer: A Python string object, either unicode or bytestring.
    :return: The PKey object.
    :rtype: :class:`PKey`
    r   r  T)r^   r   r  rS   r   rF   PEM_read_bio_PUBKEYrK   rP   r   d2i_PUBKEY_biora   r   r    r  rQ   r   r   r   )r   r=   rB   evp_pkeyr   s        r<   r1   r1   	  s     &# (w''
v

C|+DIty
 
 
		&sDI66NOOO49<<D4#566DJDKr;   c                d   t          |t                    r|                    d          }t          |          }t	          | |          }| t
          k    r@t          j        |t          j	        |j
        |j                  }|                                 n:| t          k    r t          j        |t          j	                  }nt          d          |t          j	        k    rt!                       t"                              t"                    }t          j        |t          j                  |_        |S )a  
    Load a private key (PKey) from the string *buffer* encoded with the type
    *type*.

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
    :param buffer: The buffer the key is stored in
    :param passphrase: (optional) if encrypted PEM format, this can be
                       either the passphrase to use, or a callback for
                       providing the passphrase.

    :return: The PKey object
    r   r  )r^   r   r  rS   r  r   rF   PEM_read_bio_PrivateKeyrK   rP   r  r  r  r   d2i_PrivateKey_biora   r   r    r  rQ   r   r   )r   r=   r  rB   r  r  r   s          r<   r0   r0   -	  s    " &# (w''
v

CtZ00F|/FOV-A
 
 	!!!!			*3	::NOOO49<<D4#566DJKr;   r  c                h   t                      }| t          k    rt          j        ||j                  }n]| t
          k    rt          j        ||j                  }n7| t          k    rt          j        ||j        dd          }nt          d          t          |dk               t          |          S )av  
    Dump the certificate request *req* into a buffer string encoded with the
    type *type*.

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
    :param req: The certificate request to dump
    :return: The buffer with the dumped certificate request in


    .. deprecated:: 24.2.0
       Use `cryptography.x509.CertificateSigningRequest` instead.
    r   r  )rS   r   rF   PEM_write_bio_X509_REQr  r   i2d_X509_REQ_bior   X509_REQ_print_exra   rO   rY   )r   r  rB   r  s       r<   r)   r)   V	  s     ..C|1#sx@@			+C::			,S#(AqAA
 
 	

 K1$%%%#r;   r)   c                .   t          |t                    r|                    d          }t          |          }| t          k    r6t          j        |t          j        t          j        t          j                  }n:| t          k    r t          j
        |t          j                  }nt          d          t          |t          j        k               t                              t                    }t          j        |t
          j                  |_        |S )a  
    Load a certificate request (X509Req) from the string *buffer* encoded with
    the type *type*.

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
    :param buffer: The buffer the certificate request is stored in
    :return: The X509Req object

    .. deprecated:: 24.2.0
       Use `cryptography.x509.load_der_x509_csr` or
       `cryptography.x509.load_pem_x509_csr` instead.
    r   r  )r^   r   r  rS   r   rF   PEM_read_bio_X509_REQrK   rP   r   d2i_X509_REQ_biora   rO   _X509ReqInternalr  rQ   r  r  )r   r=   rB   r  x509reqs        r<   r/   r/   	  s     &# (w''
v

C|(diDINN			#C33NOOOC49$%%%&&'788G73 233GLNr;   r/   rE   )r=   r>   r?   r	   )rB   r	   r?   rT   )rZ   r	   r[   rT   r?   r\   )r[   rT   r?   r	   )ri   r	   r?   r>   )r?   r   )r   r   r?   r   )r   r2   r=   rT   r?   r   )r   r2   r  r   r?   rT   )r   r2   r   r    r?   rT   r  )
r   r2   r   r    r  r&  r  r  r?   rT   )r   r2   r=   r  r?   r    )r   r2   r=   r  r  r  r?   r    )r   r2   r  r#   r?   rT   )r   r2   r=   rT   r?   r#   )p
__future__r   r  r1  	functoolstypingr  base64r   collections.abcr   r   r   osr   r	   r
   r   cryptographyr   r   )cryptography.hazmat.primitives.asymmetricr   r   r   r   r   OpenSSL._utilr   r  r   r  r   rK   r   rF   r   _make_assertr   r  __all__r   r   r   r   r   _PrivateKeyr   r   r   r   r   
_PublicKeyr   r   rT   r  PassphraseCallableTSSL_FILETYPE_PEMr   r  SSL_FILETYPE_ASN1r   r   r   r   EVP_PKEY_DSAr   EVP_PKEY_DHr3   EVP_PKEY_ECr4   r	  r   r   rO   rS   rY   rc   rh   rx   rz   r    r   r-   r  
deprecatedr6   r  r,   total_orderingr"   r!   r  r#   r  r   r'   r$   r&   r%   r.   r(   r+   r*   r  r1   r0   r)   r  r/   r  r:   r;   r<   <module>r1     s:   " " " " " " "               . . . . . . . .                      % $ $ $ $ $ $ $                                             : 		 		
 [*$%sE8+,E8CJ#778  ) ) ) ) )+ + + + + ! ! ! ! !! ! ! ! !            I    w:EBB ,u%%    4; ; ; ;+ + + +2   &   :
 
 
 
 
 
 
 
~. ~. ~. ~. ~. ~. ~. ~.Bd. d. d. d. d. d. d. d.N5 5 5 5 !4   	  		 	 	 	1 1 1 1$  	  		 	 	 	        Dg: g: g: g: g: g: g: g:T '   	  		 	 	 	q q q q q q q qh    	 		 	 	 	i i i i i i i iX8 8 8 8 8 8 8 8.e# e# e# e# e# e# e# e#P' ' ' ' 'I ' ' '"[ [ [ [ [ [ [ [|) ) ) ):   8   8 -1	B B B B BJK K K K K K K K\   J .2& & & & &R   @ &> "  	 	#	 	 	 	   @ &> "  	 	#	 	 	 	 	 	r;   