
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
r
S	rS
r\r " S S\5      rS rS rg)z7Helper functions for interacting with the cloudkms API.    )absolute_import)division)unicode_literals)apis)
get_digest)mapsNcloudkmsv1c                   .    \ rS rSrSrSS jrS rS rSrg)	Client"   z2A client to access cloudkms for binauthz purposes.Nc                     Uc  [         n[        R                  " [        U5      U l        [        R
                  " [        U5      U l        g)z`Creates a Cloud KMS client.

Args:
  api_version: If provided, the cloudkms API version to use.
N)DEFAULT_VERSIONr   GetClientInstanceAPI_NAMEclientGetMessagesModulemessages)selfapi_versions     4lib/googlecloudsdk/api_lib/container/binauthz/kms.py__init__Client.__init__%   s7     #k((;?DK**8[ADM    c                 ~    U R                   R                  US9nU R                  R                  R	                  U5      $ )z4Retrieves the public key for given CryptoKeyVersion.)name)r   OCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsGetPublicKeyRequestr   8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsGetPublicKey)r   key_refreqs      r   r   Client.GetPublicKey1   s=    
--
g
g h C 	LLSr   c                    [         R                  " U[        R                  " U5      5      nU R                  R                  UU R                  R                  US9S9nU R                  R                  R                  U5      $ )ad  Sign a string payload with an asymmetric KMS CryptoKeyVersion.

Args:
  key_ref: The CryptoKeyVersion relative resource name to sign with.
  digest_algorithm: The name of the digest algorithm to use in the signing
      operation. May be one of 'sha256', 'sha384', 'sha512'.
  plaintext: The plaintext bytes to sign.

Returns:
  An AsymmetricSignResponse.
)digest)r   asymmetricSignRequest)
r   GetDigestOfFilesixBytesIOr   QCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsAsymmetricSignRequestAsymmetricSignRequestr   r   AsymmetricSign)r   r    digest_algorithm	plaintextr$   r!   s         r   r+   Client.AsymmetricSign9   sx     ''#++i02F
--
i
i"mmAA B  j C
 	LLsr   )r   r   )N)	__name__
__module____qualname____firstlineno____doc__r   r   r+   __static_attributes__ r   r   r   r   "   s    :
Br   r   c                 H    U R                  5       R                  SS5      S   $ )zReturns the URI used as the default for KMS keys.

This should look something like '//cloudkms.googleapis.com/v1/...'

Args:
  key_ref: A CryptoKeyVersion Resource.

Returns:
  The string URI.
:   )SelfLinksplit)r    s    r   	GetKeyUrir;   P   s%     
				!	!#q	)!	,,r   c                 t    [         R                   H$  nXR                  R                  5       ;   d  M"  Us  $    g)zFReturns the digest name associated with the given CryptoKey Algorithm.N)r   DIGESTSr   lower)key_algorithmdigest_names     r   GetAlgorithmDigestTyperA   ^   s+    \\k((..00 "r   )r3   
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.kmsr   r   r'   r   V1r   objectr   r;   rA   r5   r   r   <module>rG      sE     > &  ' , 5 / 
	+V +\-r   