ó 9(Zc@`sØdZddlmZmZmZmZddlZddlZddlZddl m Z ddl m Z m Z mZejdkrš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 TypeErrorRRtfind(t byte_string((s2/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/pem.pytdetects cC`s¥t|tƒs.ttd||ƒƒƒ‚nt|tƒs[ttd||ƒƒƒ‚n|jƒjdƒ}tƒ}|jdƒ|j|ƒ|jdƒ|rxX|D]P}|j|jdƒƒ|jdƒ|j||jdƒƒ|jdƒq­W|jdƒnt j |ƒ}t |ƒ}d}x?||krs|j|||d !ƒ|jdƒ|d 7}q5W|jd ƒ|j|ƒ|jdƒ|j ƒS( u  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 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 RRtuppertencodeR twritetbase64t b64encodetlentgetvalue(Rt der_bytestheaderstoutputtkeyt b64_bytestb64_lenti((s2/tmp/pip-build-wDUJoH/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