
    h                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ dZ ej                  dj                  e            Zd	 Zd
 Zy)z%PEM utilities for Privateca commands.    )absolute_import)division)unicode_literalsN)
exceptionszR-----BEGIN CERTIFICATE-----\n(?:[a-zA-Z0-9+/=]+\r?\n)+-----END CERTIFICATE-----\s*z^({})+$c                     t        j                  t        |       st        j                  dd      t        j
                  t        |       }t        t        |            D ]  }||   j                         dz   ||<    |S )aH  Validates and parses a pem_chain string into a list of certs.

  Args:
    pem_chain: The string represting the pem_chain.

  Returns:
    A list of the certificates that make up the chain, in the same order
    as the input.

  Raises:
    exceptions.InvalidArgumentException if the pem_chain is in an unexpected
    format.
  z	pem-chainz7The pem_chain you provided was in an unexpected format.
)
rematch_PEM_CHAIN_REr   InvalidArgumentExceptionfindall_PEM_CERT_RErangelenstrip)	pem_chaincertsis      5lib/googlecloudsdk/command_lib/privateca/pem_utils.pyValidateAndParsePemChainr      sr     
-	+

-
-NP P **\9
-%UaQx~~$&E!H  
,    c                 h    | D cg c]  }|j                          }}dj                  |      S c c}w )zFormats a pem chain for output with exactly 1 newline character between each cert.

  Args:
    pem_chain: The list of certificate strings to output

  Returns:
    The string value of all certificates appended together for output.
  r   )r   join)r   certstripped_pem_chains      r   PemChainForOutputr   9   s4     2;;

;	%	&& <s   /)__doc__
__future__r   r   r   r	   googlecloudsdk.callioper   r   compileformatr   r   r    r   r   <module>r#      sJ    , &  ' 	 .  

:,,\:;4
'r   