o j` @sdZddlZddlZejeefZdedejeeffddZdeded edej efd d Z dededefd d Z dededefddZ dS)z0Functions that load and write PEM-encoded files.N pem_markerreturncCs,t|ts |d}d|dd|dfS)z: Returns the start and end PEM markers, as bytes. asciis -----BEGIN s-----s -----END ) isinstancebytesencode)rr)/usr/lib/python3/dist-packages/rsa/pem.py_markerss    r contents pem_startpem_endccsd}d}|D]/}|}|sq ||kr#|rtd|d}d}q |s&q |r0||kr0d}n d|vr5q |Vq |sAtd||rItd|dS)z7Generator over PEM lines between pem_start and pem_end.FzSeen start marker "%r" twiceT:zNo PEM start marker "%r" foundzNo PEM end marker "%r" foundN) splitlinesstrip ValueError)r r r in_pem_partseen_pem_startlinerrr _pem_lines&s4     rcCsJt|ts |d}t|\}}ddt|||D}d|}t|S)aLoads 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. rcSsg|]}|qSrr).0rrrr gszload_pem..)rrrr rjoinbase64standard_b64decode)r rr r pem_linespemrrr load_pemSs     rcCsrt|\}}t|dd}|g}tdt|dD]}|||d}||q|||dd|S)ajSaves 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.  rr@)r rstandard_b64encodereplacerangelenappendr)r rr r b64r block_startblockrrr save_pemns     r)) __doc__rtypingUnionstrr FlexiTextTupler Iteratorrrr)rrrr s -