§
    ¡”j  ã                   ó¦   — d Z ddlmZmZmZm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mZ ej        dk     rddlmZ ndd	lmZ d
„ Zdd„Zd„ Zdd„ZdS )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)ÚBytesIOc                 óä   — t          | t          ¦  «        s*t          t          dt	          | ¦  «        ¦  «        ¦  «        ‚|                      d¦  «        dk    p|                      d¦  «        dk    S )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   Ú	TypeErrorr   Ú
_type_nameÚfind)Úbyte_strings    ú]/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/asn1crypto/pem.pyÚdetectr      sz   € õ �k¥8Ñ,Ô,ð Ý�ðõ �{Ñ#Ô#ñ	
ô 
ñ ô ð 	ð ×Ò˜MÑ*Ô*¨bÒ0ÐY°K×4DÒ4DÀ]Ñ4SÔ4SÐWYÒ4YÐYó    c                 óž  — t          |t          ¦  «        s,t          t          dt	          |¦  «        z  ¦  «        ¦  «        ‚t          | t
          ¦  «        s*t          t          dt	          | ¦  «        ¦  «        ¦  «        ‚|                      ¦   «                              d¦  «        } t          ¦   «         }| 	                    d¦  «         | 	                    | ¦  «         | 	                    d¦  «         |rš|D ]‚}| 	                    |                     d¦  «        ¦  «         | 	                    d¦  «         | 	                    ||                              d¦  «        ¦  «         | 	                    d¦  «         Œƒ| 	                    d¦  «         t          j        |¦  «        }t          |¦  «        }d}||k     r@| 	                    |||d	z   …         ¦  «         | 	                    d¦  «         |d	z  }||k     °@| 	                    d
¦  «         | 	                    | ¦  «         | 	                    d¦  «         |                     ¦   «         S )a  
    Armors a DER-encoded byte string in PEM

    :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 der_bytes:
        A byte string to be armored

    :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 )r   r   r   r   r   r
   ÚupperÚencoder   ÚwriteÚbase64Ú	b64encodeÚlenÚgetvalue)r	   Ú	der_bytesÚheadersÚoutputÚkeyÚ	b64_bytesÚb64_lenÚis           r   Úarmorr+   2   s3  € õ( �i¥Ñ*Ô*ð Ý�ðå˜YÑ'Ô'ñ(ñ
ô 
ñ ô ð 	õ �i¥Ñ)Ô)ð Ý�ðõ �yÑ!Ô!ñ	
ô 
ñ ô ð 	ð —’Ñ!Ô!×(Ò(¨Ñ1Ô1€Iå‰YŒY€FØ
‡L‚L�Ñ Ô Ð Ø
‡L‚L�ÑÔÐØ
‡L‚L�ÑÔÐØð Øð 	 ð 	 ˆCØ�LŠL˜Ÿš GÑ,Ô,Ñ-Ô-Ð-Ø�LŠL˜ÑÔÐØ�LŠL˜ œ×,Ò,¨WÑ5Ô5Ñ6Ô6Ð6Ø�LŠL˜ÑÔÐÐØ�Š�UÑÔÐÝÔ  Ñ+Ô+€IÝ�)‰nŒn€GØ	€AØ
ˆgŠ+ˆ+Ø�Š�Y˜q  R¡˜xÔ(Ñ)Ô)Ð)Ø�Š�UÑÔÐØ	ˆR‰ˆð ˆgŠ+ˆ+ð ‡L‚L�ÑÔÐØ
‡L‚L�ÑÔÐØ
‡L‚L�ÑÔÐà�?Š?ÑÔÐr   c              #   óþ  K  — t          | t          ¦  «        s*t          t          dt	          | ¦  «        ¦  «        ¦  «        ‚d}i }d}d}d}d}|                      d¦  «        D ]ù}|dk    rŒ	|dk    rEt          j        d|¦  «        }|sŒ'|                     d¦  «         	                    d¦  «        }d	}d
}ŒT|d
k    rb| 
                    d¦  «        dk    rd}nF| 	                    d¦  «        }	|	                     dd¦  «        \  }
}|                     ¦   «         ||
<   Œ¼|dk    r7|dd…         dv r&t          j        |¦  «        }|||fV — d}i }d}d}d	}Œô||z  }Œú|r|st          t          d¦  «        ¦  «        ‚dS )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
            Útrashr   NFs1   ^(?:---- |-----)BEGIN ([A-Z0-9 ]+)(?: ----|-----)r   r   Tr%   ó   :r   Úbodyú:r   é   )s   -----s   ---- z|
            pem_bytes does not appear to contain PEM-encoded data - no
            BEGIN/END combination found
            )r   r   r   r   r   Ú
splitlinesÚreÚmatchÚgroupÚdecoder   ÚsplitÚstripr    Ú	b64decodeÚ
ValueError)Ú	pem_bytesÚstater%   Úbase64_dataÚobject_typeÚfound_startÚ	found_endÚlineÚtype_name_matchÚdecoded_lineÚnameÚvaluer$   s                r   Ú_unarmorrF   p   sô  è è € õ$ �i¥Ñ*Ô*ð Ý�ðõ �yÑ!Ô!ñ	
ô 
ñ ô ð 	ð €EØ€GØ€KØ€Kà€KØ€Ià×$Ò$ UÑ+Ô+ð & ð & ˆØ�3Š;ˆ;Øà�GÒÐõ !œhÐ'[Ð]aÑbÔbˆOØ"ð ØØ)×/Ò/°Ñ2Ô2×9Ò9¸'ÑBÔBˆKàˆKØˆEØà�IÒÐØ�yŠy˜‰Œ "Ò$Ð$Ø��à#Ÿ{š{¨7Ñ3Ô3�Ø*×0Ò0°°aÑ8Ô8‘��eØ %§¢¡¤�˜‘Øà�FŠ?ˆ?Ø�A�a�CŒyÐ0Ð0Ð0Ý"Ô,¨[Ñ9Ô9�	à" G¨YÐ7Ð7Ð7Ð7à�Ø�Ø!�Ø"�Ø �	Øà˜4ÑˆKøàð ˜ið Ý�ðñ
ô 
ñ ô ð 	ðð r   Fc                 óF   — t          | ¦  «        }|st          |¦  «        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.
    )rF   Únext)r;   ÚmultipleÚ	generators      r   ÚunarmorrK   Ä   s+   € õ* ˜Ñ#Ô#€Iàð Ý�I‰ŒÐàÐr   )N)F)Ú__doc__Ú
__future__r   r   r   r   r    r3   ÚsysÚ_errorsr   Ú_typesr	   r   r
   r   Úversion_infoÚ	cStringIOr   r   Úior   r+   rF   rK   © r   r   ú<module>rU      s  ððð ð SÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Rà €€€Ø 	€	€	€	Ø 
€
€
€
à Ð Ð Ð Ð Ð Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ð >àÔ�dÒÐØ-Ð-Ð-Ð-Ð-Ð-Ð-àÐÐÐÐÐðZð Zð Zð.;ð ;ð ;ð ;ð|Qð Qð Qðhð ð ð ð ð r   