MOON
Server: Apache
System: Linux server30c.hostingraja.org 3.10.0-962.3.2.lve1.5.63.el7.x86_64 #1 SMP Fri Oct 8 12:03:35 UTC 2021 x86_64
User: jibhires (1887)
PHP: 8.1.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, allow_url_fopen, symlink, escapeshellcmd, pcntl_exec
Upload Files
File: //opt/alt/python38/lib/python3.8/site-packages/asn1crypto/__pycache__/pem.cpython-38.opt-1.pyc
U

�rV��@s�dZddlmZmZmZmZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZejdkrlddlmZndd	lmZd
d�Zddd
�Zdd�Zddd�ZdS)zq
Encoding DER to PEM and decoding PEM to DER. Exports the following items:

 - armor()
 - detect()
 - unarmor()

�)�unicode_literals�division�absolute_import�print_functionN�)�unwrap)�	type_name�str_cls�byte_cls)�)�StringIO)�BytesIOcCs8t|t�sttdt|����|�d�dkp6|�d�dkS)z�
    Detect if a byte string seems to contain a PEM-encoded block

    :param byte_string:
        A byte string to look through

    :return:
        A boolean, indicating if a PEM-encoded block is contained in the byte
        string
    zC
            byte_string must be a byte string, not %s
            s
-----BEGIN���s
---- BEGIN)�
isinstancer
�	TypeErrorrr�find)Zbyte_string�r�/pem.py�detects
�rcCs,t|t�sttd||����t|t�s:ttd||����|���d�}t�}|�d�|�|�|�d�|r�|D]<}|�|�d��|�d�|�||�d��|�d�qt|�d�t	�
|�}t|�}d}||k�r|�|||d	��|�d�|d	7}q�|�d
�|�|�|�d�|��S)a

    Armors a DER-encoded byte string in PEM

    :param der_bytes:
        A byte string to be armored

    :param type_name:
        A unicode string that will be capitalized and placed in the header
        and footer of the block. E.g. "CERTIFICATE", "PRIVATE KEY", etc. This
        will appear as "-----BEGIN CERTIFICATE-----" and
        "-----END CERTIFICATE-----".

    :param headers:
        An OrderedDict of the header lines to write after the BEGIN line

    :return:
        A byte string of the PEM block
    zA
            der_bytes must be a byte string, not %s
            zD
            type_name must be a unicode string, not %s
            �asciis-----BEGIN s-----
s: �
r�@s	-----END )
rr
rrr	�upper�encoder
�write�base64Z	b64encode�len�getvalue)r�	der_bytes�headers�output�keyZ	b64_bytesZb64_len�irrr�armor2sD
��
�











r#c
cs0t|t�sttdt|����d}i}d}d}d}d}|�d�D]�}|dkrLq>|dkr�t�d|�}|sfq>|�d��	d�}d	}d
}q>|d
kr�|�
d�dkr�d
}n(|�	d�}	|	�dd�\}
}|��||
<q>|d
kr>|dd�dk�r
t
�|�}|||fVd}i}d}d}d	}q>||7}q>|�r |�s,ttd���dS)ax
    Convert a PEM-encoded byte string into one or more DER-encoded byte strings

    :param pem_bytes:
        A byte string of the PEM-encoded data

    :raises:
        ValueError - when the pem_bytes do not appear to be PEM-encoded bytes

    :return:
        A generator of 3-element tuples in the format: (object_type, headers,
        der_bytes). The object_type is a unicode string of what is between
        "-----BEGIN " and "-----". Examples include: "CERTIFICATE",
        "PUBLIC KEY", "PRIVATE KEY". The headers is a dict containing any lines
        in the form "Name: Value" that are right after the begin line.
    zA
            pem_bytes must be a byte string, not %s
            Ztrash�NFs1^(?:---- |-----)BEGIN ([A-Z0-9 ]+)(?: ----|-----)rrTr�:rZbody�:r�)s-----s---- z|
            pem_bytes does not appear to contain PEM-encoded data - no
            BEGIN/END combination found
            )rr
rrr�
splitlines�re�match�group�decoder�split�striprZ	b64decode�
ValueError)
�	pem_bytes�staterZbase64_dataZobject_typeZfound_startZ	found_end�lineZtype_name_matchZdecoded_line�name�valuerrrr�_unarmorpsX
�


�r5FcCst|�}|st|�S|S)a�
    Convert a PEM-encoded byte string into a DER-encoded byte string

    :param pem_bytes:
        A byte string of the PEM-encoded data

    :param multiple:
        If True, function will return a generator

    :raises:
        ValueError - when the pem_bytes do not appear to be PEM-encoded bytes

    :return:
        A 3-element tuple (object_name, headers, der_bytes). The object_name is
        a unicode string of what is between "-----BEGIN " and "-----". Examples
        include: "CERTIFICATE", "PUBLIC KEY", "PRIVATE KEY". The headers is a
        dict containing any lines in the form "Name: Value" that are right
        after the begin line.
    )r5�next)r0Zmultiple�	generatorrrr�unarmor�sr8)N)F)�__doc__Z
__future__rrrrrr)�sysZ_errorsrZ_typesrr	r
�version_infoZ	cStringIOrr
�iorr#r5r8rrrr�<module>s	

>T