ó Ü_e[c@`sØdZddlmZmZmZmZddlZddlZddlZddl m Z ddl m Z mZmZejdkršddlmZndd lmZd „Zdd „Zd „Zed „ZdS(uq Encoding DER to PEM and decoding PEM to DER. Exports the following items: - armor() - detect() - unarmor() i(tunicode_literalstdivisiontabsolute_importtprint_functionNi(tunwrap(t type_nametstr_clstbyte_clsi(tStringIO(tBytesIOcC`sUt|tƒs-ttdt|ƒƒƒ‚n|jdƒdkpT|jdƒdkS(uð 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 uC byte_string must be a byte string, not %s s -----BEGINiÿÿÿÿs ---- BEGIN(t isinstanceRt TypeErrorRt _type_nametfind(t byte_string((s4/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/pem.pytdetects cC`s¥t|tƒs.ttdt|ƒƒƒ‚nt|tƒs[ttdt|ƒƒƒ‚n|jƒjdƒ}tƒ}|j dƒ|j |ƒ|j dƒ|rxX|D]P}|j |jdƒƒ|j dƒ|j ||jdƒƒ|j dƒq­W|j dƒnt j |ƒ}t |ƒ}d}x?||krs|j |||d !ƒ|j dƒ|d 7}q5W|j d ƒ|j |ƒ|j dƒ|j ƒS( u  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 uA der_bytes must be a byte string, not %s uD type_name must be a unicode string, not %s uasciis -----BEGIN s----- s: s ii@s -----END (R RR RR RtuppertencodeR twritetbase64t b64encodetlentgetvalue(Rt der_bytestheaderstoutputtkeyt b64_bytestb64_lenti((s4/tmp/pip-install-KP2Jbq/asn1crypto/asn1crypto/pem.pytarmor2s<           c c`sÌt|tƒs-ttdt|ƒƒƒ‚nd}i}d}d}t}t}xQ|jtƒD]@}|dkryqan|dkrÍtj d|ƒ}|s£qan|j dƒj dƒ}t }d}qan|dkr4|j dƒd kr÷d }q4|j dƒ} | jd dƒ\} } | jƒ|| s"     > T