File: //lib/python3/dist-packages/OpenSSL/__pycache__/crypto.cpython-312.pyc
�
��Saӛ � �> � d dl Z d dlZd dlmZ d dlmZ d dlmZmZm Z m
Z
mZmZ d dl
mZmZmZ d dlmZmZ d dlmZmZ d dlmZmZmZ m!Z"m#Z$m%Z&m'Z(m)Z*m+Z, g d �Z-ej\ Z/ej` Z1d
Z2ejf Z4ejj Z6ejn Z8ejr Z: G d� de;� Z< ee e<� Z= e,e<� Z>d
� Z?d� Z@dHd�ZAd� ZBd� ZCd� ZD G d� deE� ZF G d� deE� ZG G d� deE� ZHd� ZId� ZJ G d� deE� ZK G d� deE� ZL G d� d eE� ZM G d!� d"eE� ZN G d#� d$eE� ZO G d%� d&eE� ZP G d'� d(e;� ZQ G d)� d*eE� ZRd+� ZSd,� ZTd-� ZUdId.�ZV G d/� d0eE� ZW G d1� d2eE� ZX G d3� d4eE� ZY G d5� d6eE� ZZ G d7� d8eE� Z[ G d9� d:eE� Z\d;� Z]dHd<�Z^d=� Z_d>� Z`d?� Zad@� ZbdA� ZcdB� ZddC� Ze ej� eeegdDeh� ZedHdE�Zi ej� eiegdFeh� Zi ej� � ej� � ej� dG� y)J� N)� b16encode)�partial)�__eq__�__ne__�__lt__�__le__�__gt__�__ge__)�
integer_types� text_type�PY2)�utils�x509)�dsa�rsa) �ffi�lib�exception_from_error_queue�byte_string�native�path_string�UNSPECIFIED�text_to_bytes_and_warn�make_assert)$�FILETYPE_PEM�
FILETYPE_ASN1�
FILETYPE_TEXT�TYPE_RSA�TYPE_DSA�Error�PKey�get_elliptic_curves�get_elliptic_curve�X509Name�
X509Extension�X509Req�X509�X509StoreFlags� X509Store�X509StoreContextError�X509StoreContext�load_certificate�dump_certificate�dump_publickey�dump_privatekey�Revoked�CRL�PKCS7�PKCS12�NetscapeSPKI�load_publickey�load_privatekey�dump_certificate_request�load_certificate_request�sign�verify�dump_crl�load_crl�load_pkcs7_data�load_pkcs12i�� c � � e Zd ZdZy)r z7
An error occurred in an `OpenSSL.crypto` API.
N)�__name__�
__module__�__qualname__�__doc__� � �0/usr/lib/python3/dist-packages/OpenSSL/crypto.pyr r P s � �rE r c � � ddl m} | S )ap
Importing the backend from cryptography has the side effect of activating
the osrandom engine. This mutates the global state of OpenSSL in the
process and causes issues for various programs that use subinterpreters or
embed Python. By putting the import in this function we can avoid
triggering this side effect unless _get_backend is called.
r ��backend)�,cryptography.hazmat.backends.openssl.backendrI rH s rF �_get_backendrK Z s
� � E��NrE c � � t d| �d�� �)z�
An OpenSSL API failed somehow. Additionally, the failure which was
encountered isn't one that's exercised by the test suite so future behavior
of pyOpenSSL is now somewhat less predictable.
zUnknown z failure)�RuntimeError)�wheres rF �_untested_errorrO g s � � �u�6�
7�7rE c �R � | �8t j t j � � }t j }n:t j
d| � }t j |t | � � }|fd�}t |t j k7 � 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.
�char[]c �, � t j | � S �N)�_lib�BIO_free)�bio�refs rF �freez_new_mem_buf.<locals>.free� s � ��=�=��%�%rE )rT �BIO_new� BIO_s_memrU �_ffi�new�BIO_new_mem_buf�len�_openssl_assert�NULL�gc)�bufferrV rX �datas rF �_new_mem_bufrd p s � � �~��l�l�4�>�>�+�,���}�}���x�x��&�)���"�"�4��V��5�� � &� �C�4�9�9�$�%�
�'�'�#�t�
�C��JrE c � � t j d� }t j | |� }t j |d |� dd S )zO
Copy the contents of an OpenSSL BIO object into a Python byte string.
zchar**r N)r[ r\ rT �BIO_get_mem_datarb )rV �
result_buffer�
buffer_lengths rF �_bio_to_stringri � s? � � �H�H�X�&�M��)�)�#�}�=�M��;�;�}�Q�'��7��:�:rE c � � t |t � st d� �t j | |� }|dk( rt d� �y)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.
zwhen must be a byte stringr zInvalid stringN)�
isinstance�bytes� TypeErrorrT �ASN1_TIME_set_string�
ValueError)�boundary�when�
set_results rF �_set_asn1_timers � sD � � �d�E�"��4�5�5��*�*�8�T�:�J��Q���)�*�*� rE c �P � t j d| � }t j |� dk( ryt j |� t j
k( r(t j t j |� � S t j d� }t j | |� |d t j k( rt d� yt 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 NzASN1_GENERALIZEDTIME**�ASN1_TIME_to_generalizedtime)
r[ �castrT �ASN1_STRING_length�ASN1_STRING_type�V_ASN1_GENERALIZEDTIME�string�ASN1_STRING_datar\ rv r` rO �ASN1_GENERALIZEDTIME_free)� timestamp�string_timestamp�generalized_timestamp�string_data�
string_results rF �_get_asn1_timer� � s� � � �y�y���;�����/�0�A�5�����.�/�4�3N�3N�N��{�{�4�0�0�1A�B�C�C� $���)A� B���)�)�)�5J�K� ��#�t�y�y�0�
�:�;�#�y�y�� 5�a� 8� �� �/�/�0@�A�K� �K�K��4�M��*�*�+@��+C�D� � rE c � � e Zd Zd� Zd� Zd� Zy)�_X509NameInvalidatorc � � g | _ y rS )�_names��selfs rF �__init__z_X509NameInvalidator.__init__� s � ���rE c �: � | j j |� y rS )r� �append�r� �names rF �addz_X509NameInvalidator.add� s � ������4� rE c �* � | j D ] }|`� y rS )r� �_namer� s rF �clearz_X509NameInvalidator.clear� s � ��K�K�D��
� rE N)r@ rA rB r� r� r� rD rE rF r� r� � s � ��!�rE r� c �L � e Zd ZdZdZdZd� Zd� Zed� � Z d� Z
d� Zd � Zd
� Z
y)r! zD
A class representing an DSA or RSA public key or key pair.
FTc � � t j � }t j |t j � | _ d| _ y )NF)rT �EVP_PKEY_newr[ ra �
EVP_PKEY_free�_pkey�_initialized�r� �pkeys rF r� z
PKey.__init__� s0 � �� � �"���W�W�T�4�#5�#5�6��
�!��rE c � � ddl m}m} t � }| j rt 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� rK �_only_publicr. r r/ )r� r� r� rI �ders rF �to_cryptography_keyzPKey.to_cryptography_key� sM � �
�
�.����� ���5�C�&�s�G�4�4�!�-��6�C�'��T�7�;�;rE c �� � t |t j t j t j
t j f� st d� �ddlm }m
}m}m} t |t j t j
f� r4t t |j |j |j"