3 M(ÌYÑ ã@s8dZddlZddlmZmZdd„Zdd„Zdd „ZdS) z0Functions that load and write PEM-encoded files.éN)ÚbÚis_bytescCs*t|ƒr|jdƒ}td|ƒtd|ƒfS)z/ Returns the start and end PEM markers zutf-8z-----BEGIN %s-----z-----END %s-----)rÚdecoder)Ú pem_marker©rú./private/tmp/pip-build-nl73fm5q/rsa/rsa/pem.pyÚ_markerss  rcCsÌt|ƒs|jdƒ}t|ƒ\}}g}d}xl|jƒD]`}|jƒ}|sBq0||kr`|rZtd|ƒ‚d}q0|sfq0|rx||krxd}Ptdƒ|kr†q0|j|ƒq0W|s¤td|ƒ‚|r´td|ƒ‚tdƒj|ƒ}t j |ƒS) 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. ÚasciiFzSeen start marker "%s" twiceTú:zNo PEM start marker "%s" foundzNo PEM end marker "%s" foundÚ) rÚencoderÚ splitlinesÚstripÚ ValueErrorrÚappendÚjoinÚbase64Ústandard_b64decode)ÚcontentsrÚ pem_startÚpem_endÚ pem_linesZ in_pem_partÚlineZpemrrrÚload_pem#s8       rcCs†t|ƒ\}}tj|ƒjtdƒtdƒƒ}|g}x2tdt|ƒdƒD]}|||d…}|j|ƒq>W|j|ƒ|jtdƒƒtdƒj|ƒS)a`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. Ú r ré@) rrÚstandard_b64encodeÚreplacerÚrangeÚlenrr)rrrrZb64rZ block_startÚblockrrrÚsave_pemes  r!)Ú__doc__rZ rsa._compatrrrrr!rrrrÚs  B