File: //lib/python3.9/site-packages/OpenSSL/__pycache__/crypto.cpython-39.pyc
a
�Saӛ � @ s 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/ej0Z1d
Z2ej3Z4ej5Z6ej7Z8ej9Z:G dd� de;�Z<ee e<�Z=e,e<�Z>d
d� Z?dd� Z@d^dd�ZAdd� ZBdd� ZCdd� ZDG dd� deE�ZFG dd� deE�ZGG dd� deE�ZHdd � ZId!d"� ZJG d#d$� d$eE�ZKG d%d&� d&eE�ZLG d'd(� d(eE�ZMG d)d*� d*eE�ZNG d+d,� d,eE�ZOG d-d.� d.eE�ZPG d/d0� d0e;�ZQG d1d2� d2eE�ZRd3d4� ZSd5d6� ZTd7d8� ZUd_d9d:�ZVG d;d<� d<eE�ZWG d=d>� d>eE�ZXG d?d@� d@eE�ZYG dAdB� dBeE�ZZG dCdD� dDeE�Z[G dEdF� dFeE�Z\dGdH� Z]d`dIdJ�Z^dKdL� Z_dMdN� Z`dOdP� ZadQdR� ZbdSdT� ZcdUdV� ZddWdX� Zee�feeegdYeh�ZedadZd[�Zie�feiegd\eh�Zie�j� e�k� e�ld]� dS )b� 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 @ s e Zd ZdZdS )r z7
An error occurred in an `OpenSSL.crypto` API.
N)�__name__�
__module__�__qualname__�__doc__� rB rB �2/usr/lib/python3.9/site-packages/OpenSSL/crypto.pyr P s r c C s 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)Z,cryptography.hazmat.backends.openssl.backendrE rD rB rB rC �_get_backendZ s rF c C s t d| f ��dS )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 %s failureN)�RuntimeError)�whererB rB rC �_untested_errorg s rI c C sd | du rt �t �� �}t j}n(t�d| �}t �|t| ��}|fdd�}t|tj k� t�
||�}|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[]c S s
t �| �S �N)�_lib�BIO_free)�bio�refrB rB rC �free� s z_new_mem_buf.<locals>.free)rL �BIO_new� BIO_s_memrM �_ffi�newZBIO_new_mem_buf�len�_openssl_assert�NULL�gc)�bufferrN rP �datarB rB rC �_new_mem_bufp s r[ c C s. t �d�}t�| |�}t �|d |�dd� S )zO
Copy the contents of an OpenSSL BIO object into a Python byte string.
zchar**r N)rS rT rL ZBIO_get_mem_datarY )rN �
result_bufferZ
buffer_lengthrB rB rC �_bio_to_string� s
r] c C s2 t |t�std��t�| |�}|dkr.td��dS )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� TypeErrorrL ZASN1_TIME_set_string�
ValueError)�boundary�when�
set_resultrB rB rC �_set_asn1_time� s
re c C s� t �d| �}t�|�dkrdS t�|�tjkr>t �t�|��S t �d�}t� | |� |d t j
krltd� n6t �d|d �}t�|�}t �|�}t�|d � |S dS )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)
rS �castrL �ASN1_STRING_lengthZASN1_STRING_typeZV_ASN1_GENERALIZEDTIME�string�ASN1_STRING_datarT rg rW rI ZASN1_GENERALIZEDTIME_free)Z timestampZstring_timestampZgeneralized_timestampZstring_data�
string_resultrB rB rC �_get_asn1_time� s"