HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: //lib/google-cloud-sdk/lib/surface/kms/__pycache__/decapsulate.cpython-312.pyc
�

�������dZddlmZddlmZddlmZddlmZddlm	Z
ddlm	Z	ddlmZddlm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZe	j,Gd
�de	j.��Zy)z@Decapsulate an input file using a key-encapsulation key version.�)�absolute_import)�division)�unicode_literals)�
exceptions)�base)�crc32c)�
e2e_integrity)�flags)�log)�
console_io)�filesc�8�eZdZdZed��Zd�Zd�Zd�Zd�Z	y)�DecapsulateaDDecapsulate an input file using a key-encapsulation key version.

  Decapsulates the given ciphertext file using the provided key-encapsulation
  key version and saves the decapsulated shared secret to the shared secret file.

  By default, the command performs integrity verification on data sent to and
  received from Cloud KMS. Use `--skip-integrity-verification` to disable
  integrity verification.

  ## EXAMPLES
  The following command will read the file '/tmp/my/secret.file.enc', decapsulate it
  using the key encapsulation CryptoKey `my-key` Version 3 and write the shared secret
  to '/tmp/my/secret.file.dec'.

    $ {command} \
    --location=us-central1 \
    --keyring=my-keyring \
    --key=my-key \
    --version=3 \
    --ciphertext-file=/tmp/my/secret.file.enc \
    --shared-secret-file=/tmp/my/secret.file.dec

  c���tj|d�tj|d�tj|d�tj|d�tj
|�y)Nzto use for decapsulation.zto use for decapsulationzto decapsulatez	to output)r
�AddKeyResourceFlags�AddCryptoKeyVersionFlag�AddCiphertextFileFlag�AddSharedSecretFileFlag�AddSkipIntegrityVerification)�parsers �lib/surface/kms/decapsulate.py�ArgszDecapsulate.Args;sS��	���f�&A�B�	�!�!�&�*D�E�	����(8�9�	�!�!�&�+�6�	�&�&�v�.�c��|jS)N)�skip_integrity_verification)�self�argss  r�_PerformIntegrityVerificationz)Decapsulate._PerformIntegrityVerificationCs���/�/�/�/rc��	tj|jd��}tj�}tj|�}|j|j���}|j|�r/tj |�}|j#||��|_|S|j#|��|_|S#tj$r4}tjdj|j|���d}~wwxYw)NT)�binaryz)Failed to read ciphertext file [{0}]: {1})�name)�
ciphertext�ciphertextCrc32c)r")r�ReadFromFileOrStdin�ciphertext_filer
�Errorr�BadFileException�format�
cloudkms_base�GetMessagesModuler
�ParseCryptoKeyVersionName�NCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsDecapsulateRequest�RelativeNamerr�Crc32c�DecapsulateRequest�decapsulateRequest)rrr"�e�messages�crypto_key_ref�req�ciphertext_crc32cs        r�_CreateDecapsulateRequestz%Decapsulate._CreateDecapsulateRequestFs��(��1�1�
�
�
�t�-�j��.�.�0�H��4�4�T�:�N�
�
a�
a�
�
(�
(�
*�b��C��)�)�$�/� �-�-�
�3��'�:�:��2C� ;� �c���J�	 (�:�:�� ;� �c���J��+�;�;�(��'�'�
5�
<�
<��"�"�A�'�
(�(��(�s�!C�D�/D�Dc��|js'tjtj���t	j
|j|j�s'tjtj���y)z&Verifies integrity fields in response.N)	�verifiedCiphertextCrc32cr	�$ClientSideIntegrityVerificationError�'GetRequestToServerCorruptedErrorMessager�
Crc32cMatches�sharedSecret�sharedSecretCrc32c�*GetResponseFromServerCorruptedErrorMessage)rr4�resps   r�_VerifyResponseIntegrityFieldsz*Decapsulate._VerifyResponseIntegrityFieldsass���(�(��>�>�
�
?�
?�
A�
C�C����� 1� 1�4�3J�3J�K��>�>�
�
B�
B�
D�
F�F�Lrc���|j|�}tj�}	|jj	|�}|j|�r|j
||�tj|j|jxsdddd��y#tj$r}tj|�Yd}~yd}~wtj $r}t#j$|��d}~wwxYw)N�T)�	overwriter �private)r6r)�GetClientInstance�8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsrrr@r�WriteToFileOrStdout�shared_secret_filer<�apitools_exceptions�HttpBadRequestErrorr	�ProcessHttpBadRequestErrorr
r&rr')rrr4�clientr?�errorr1s       r�RunzDecapsulate.Runns���
�
(�
(��
.�C�
�
,�
,�
.�F�+�
�
L�
L�
X�
X�

��d�
�	+�	+�D�	1��+�+�C��6�	���
�
!�
!�
�
�
�
!�r�������2�2�6��.�.�u�5�5���;�;�+��'�'��*�*��+�s$�A0B�C5�+C�C5�C0�0C5N)
�__name__�
__module__�__qualname__�__doc__�staticmethodrrr6r@rN�rrrr!s0���0�/��/�0��6F�+rrN)rR�
__future__rrr�apitools.base.pyrrI�googlecloudsdk.api_lib.cloudkmsrr)�googlecloudsdk.calliope�googlecloudsdk.command_lib.kmsrr	r
�googlecloudsdk.corer�googlecloudsdk.core.consoler�googlecloudsdk.core.utilr
�UniverseCompatible�CommandrrTrr�<module>r_sZ��G�&��'�>�A�(�.�1�8�0�#�2�*����d+�$�,�,�d+��d+r