Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib
/
python3.5
/
site-packages
/
asn1crypto
/
__pycache__
/
File Content:
pem.cpython-35.pyc
�rV� � @ s� 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 d � Z d d d � Z d d � Z d 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 C sR t | t � s* t t d t | � � � � | j d � d k pQ | j 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 -----BEGINr s ---- BEGIN���r )� isinstancer � TypeErrorr r �find)Zbyte_string� r �/pem.py�detect s r c C s� t | t � s+ t t d | | � � � � t | t � sU t t d | | � � � � | j � j d � } t � } | j d � | j | � | j d � | rxX | D]P } | j | j d � � | j d � | j | | j d � � | j d � q� W| j d � t j | � } t | � } d } xB | | k rm| j | | | d � � | j d � | d 7} q,W| j d � | j | � | j d � | j � 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 : s r �@ s -----END ) r r r r r �upper�encoder �write�base64Z b64encode�len�getvalue)r � der_bytes�headers�output�keyZ b64_bytesZb64_len�ir r r �armor2 s<