U BBû`ã@s dZddlmZmZmZmZddlZddlZddlZddl m Z ddl m Z mZmZejdkrlddlmZn 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 Ú TypeErrorrÚ _type_nameÚfind)Z byte_string©rú]C:\Users\shjeevan\PycharmProjects\Verisk-XactWare\venv3.8\Lib\site-packages\asn1crypto/pem.pyÚdetects ürcCs,t|tƒsttdt|ƒƒƒ‚t|tƒs:ttdt|ƒƒƒ‚| ¡ 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 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 )rr rrrr ÚupperÚencoder ÚwriteÚbase64Ú 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!ó:rÚbodyú: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ÚstriprÚ b64decodeÚ ValueError) Ú pem_bytesÚstater!Z base64_dataZ object_typeZ found_startZ found_endÚlineZtype_name_matchZ decoded_lineÚnameÚvaluer rrrÚ_unarmorpsX ü       ÿr9FcCst|ƒ}|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. )r9Únext)r4ÚmultipleÚ generatorrrrÚunarmorÄsr=)N)F)Ú__doc__Ú __future__rrrrrr,ÚsysÚ_errorsrÚ_typesrrr r Ú version_infoÚ cStringIOr r Úiorr%r9r=rrrrÚs     >T