
    g              	           d Z ddlZddlZej                  eef   Zdedej                  eef   fdZdedededej                  e   fd	Z
dededefd
ZdededefdZy)z0Functions that load and write PEM-encoded files.    N
pem_markerreturnc                 d    t        | t              s| j                  d      } d| z   dz   d| z   dz   fS )z:
    Returns the start and end PEM markers, as bytes.
    asciis   -----BEGIN s   -----s	   -----END )
isinstancebytesencode)r   s    </var/www/openai/venv/lib/python3.12/site-packages/rsa/pem.py_markersr      sD    
 j%(&&w/
 	#h.z!H,     contents	pem_startpem_endc              #     K   d}d}| j                         D ]F  }|j                         }|s||k(  r|rt        d|z        d}d}0|s3|r	||k(  rd} nd|v rC| H |st        d|z        |rt        d|z        yw)z7Generator over PEM lines between pem_start and pem_end.FzSeen start marker "%r" twiceT   :zNo PEM start marker "%r" foundzNo PEM end marker "%r" foundN)
splitlinesstrip
ValueError)r   r   r   in_pem_partseen_pem_startlines         r
   
_pem_linesr   &   s      KN##%zz|  9 !?)!KLLK!N  47?K 4<
; &@ 9IEFF7'ABB s   A?Bc                     t        | t              s| j                  d      } t        |      \  }}t	        | ||      D cg c]  }| }}dj                  |      }t        j                  |      S c c}w )a  Loads a PEM file.

    :param contents: the contents of the file to interpret
    :param pem_marker: the marker of the PEM content, such as 'RSA PRIVATE KEY'
        when your file has '-----BEGIN RSA PRIVATE KEY-----' and
        '-----END RSA PRIVATE KEY-----' markers.

    :return: the base64-decoded content between the start and end markers.

    @raise ValueError: when the content is invalid, for example when the start
        marker cannot be found.

    r   r   )r   r   r	   r   r   joinbase64standard_b64decode)r   r   r   r   r   	pem_linespems          r
   load_pemr   S   sq      h&??7+#J/Y",Xy'"JK"J$"JIK ((9
C$$S))	 Ls   	A0c                 <   t        |      \  }}t        j                  |       j                  dd      }|g}t	        dt        |      d      D ]  }|||dz    }|j                  |        |j                  |       |j                  d       dj                  |      S )aj  Saves a PEM file.

    :param contents: the contents to encode in PEM format
    :param pem_marker: the marker of the PEM content, such as 'RSA PRIVATE KEY'
        when your file has '-----BEGIN RSA PRIVATE KEY-----' and
        '-----END RSA PRIVATE KEY-----' markers.

    :return: the base64-encoded content between the start and end markers, as bytes.

       
r   r   @   )r   r   standard_b64encodereplacerangelenappendr   )r   r   r   r   b64r   block_startblocks           r
   save_pemr+   n   s     $J/Y

#
#H
-
5
5eS
ACIQC"-K+"23 . WS::i  r   )__doc__r   typingUnionstrr   	FlexiTextTupler   Iteratorr   r   r+    r   r
   <module>r4      s    7   LLe$	 v||E5L'A *C *C5 *C5 *CV__UZE[ *CZ*y *i *E *6!u !) ! !r   