
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddl
mZ dd	lmZ ej                   G d
 dej                                Zy)z'Get the public key for a given version.    )absolute_import)division)unicode_literals)base)
exceptions)flags)maps)logc                   &    e Zd ZdZed        Zd Zy)GetPublicKeyaA  Get the public key for a given version.

  Returns the public key of the given asymmetric key version in the specified format.

  The optional flag `output-file` indicates the path to store the public key.
  If not specified, the public key will be printed to stdout.

  The optional flag `public-key-format` indicates the format in which the
  public key will be returned. For the NIST PQC algorithms, this must be
  specified and set to `nist-pqc`. For kem-xwing this must be specified and set to
  `xwing-raw-bytes`. For all other algorithms, this flag is
  optional and can be either `pem` or `der`; the default value is `pem`.
  See "Retrieve a public key" in the Cloud KMS
  documentation (https://cloud.google.com/kms/help/get-public-key) for more
  information about the supported formats.

  ## EXAMPLES

  The following command saves the public key for CryptoKey `frodo` Version 2
  to '/tmp/my/public_key.file':

    $ {command} 2 \
    --key=frodo \
    --keyring=fellowship \
    --location=us-east1 \
    --public-key-format=pem \
    --output-file=/tmp/my/public_key.file
  c                     t        j                  | d       t        j                  | d       t        j                  |        y )Nzto get public keyzto store public key)r   AddKeyVersionResourceArgumentAddOutputFileFlagAddPublicKeyFormatFlag)parsers    /lib/surface/kms/keys/versions/get_public_key.pyArgszGetPublicKey.Args<   s2    	''0CD	F$9:	  (    c                    t        j                         }t        j                         }t        j                  |      }|j                         st        j                  dd      |j                  |j                               }|j                  rR|j                  dvrt        j                  dd      t        j                  j                  |j                        |_        |j                  j!                  |      }|j                  dv }t#        j$                  |j&                  r|j&                  nd|j(                  r|j(                  n|j*                  j,                  d	|d	
       y )Nversionzversion id must be non-empty.)name)pemdernist-pqcxwing-raw-bytesz--public-key-formatziInvalid value for public key format. Supported values are "der", "pem", "xwing-raw-bytes" and "nist-pqc".)r   r   r   -T)	overwritebinaryprivate)cloudkms_baseGetClientInstanceGetMessagesModuler   ParseCryptoKeyVersionNameNamer   InvalidArgumentExceptionOCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsGetPublicKeyRequestRelativeNamepublic_key_formatr	   PUBLIC_KEY_FORMAT_MAPPERGetEnumForChoicepublicKeyFormat8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsr   r
   WriteToFileOrStdoutoutput_filer   	publicKeydata)selfargsclientmessagesversion_refreqrespwrite_binary_files           r   RunzGetPublicKey.RunB   sN   ,,.F..0H11$7K//
4  
b
b%%' c C 			 ( 
 11!8
 	

 !99JJ

 
 c JJWWD .. 3 
  ,,#HH$.."5"5 r   N)__name__
__module____qualname____doc__staticmethodr   r9    r   r   r   r      s     : ) )
,r   r   N)r=   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   r    googlecloudsdk.callioper   googlecloudsdk.command_lib.kmsr   r	   googlecloudsdk.corer
   UniverseCompatibleDescribeCommandr   r?   r   r   <module>rG      sO    . &  ' A ( . 0 / # P4'' P Pr   