
                             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dlmZ	 dZ
 G d d	e	j                        Z G d
 de	j                        Z G d de	j                        Zd Zd Zd Zd Zy)z.Helpers for End to End integirty verification.    )absolute_import)division)unicode_literalsN)
exceptionszPlease try again. This should happen rarely. If the error persists, contact cloudkms-feedback@google.com. To learn more about how Cloud KMS verifies in-transit integrity, visit https://cloud.google.com/kms/docs/data-integrity-guidelines.c                       e Zd ZdZy)$ServerSideIntegrityVerificationErrorz?Error raised when server reported integrity verification error.N__name__
__module____qualname____doc__     3lib/googlecloudsdk/command_lib/kms/e2e_integrity.pyr   r   !   s    Gr   r   c                       e Zd ZdZy)$ClientSideIntegrityVerificationErrorzAError raised when client identifies integrity verification error.Nr	   r   r   r   r   r   %   s    Ir   r   c                       e Zd ZdZy)ResourceNameVerificationErrorz[Error raised when server returned resource name differs from client provided resource name.Nr	   r   r   r   r   r   )   s    cr   r   c                  ,    dj                  t              S )zGError message for when the request to server failed an integrity check.z;The request sent to the server was corrupted in-transit. {}format_ERROR_MESSAGE_SUFFIXr   r   r   'GetRequestToServerCorruptedErrorMessager   -   s     H
N
N r   c                  ,    dj                  t              S )zJError message for when the response from server failed an integrity check.zBThe response received from the server was corrupted in-transit. {}r   r   r   r   *GetResponseFromServerCorruptedErrorMessager   4   s     O6'(*r   c                 V    dj                  |       dj                  |      z   t        z   S )Nz<Found a mismatch between user-requested crypto resource ({})zHand server-reported resource used for the cryptographic operation ({}).
r   )request_resource_nameresponse_resource_names     r   #GetResourceNameMismatchErrorMessager   ;   s8     EKK
!Qv$%& )>>?r   c                     t        j                  |       }t        j                  d      }|j	                  |j
                  j                        t        t                     |)a  Intercept INVALID_ARGUMENT errors related to checksum verification.

  Intercept INVALID_ARGUMENT errors related to checksum verification, to present
  a user-friendly message.
  All other errors are surfaced as-is.
  Args:
    error: apitools_exceptions.ProcessHttpBadRequestError.

  Raises:
    ServerSideIntegrityVerificationError: if |error| is a result of a failed
    server-side request integrity verification.
    Else, re-raises |error| as exceptions.HttpException.
  z<The checksum in field .* did not match the data in field .*.)	r   HttpExceptionrecompilesearchpayloadstatus_messager   r   )errorexcregexs      r   ProcessHttpBadRequestErrorr*   E   sY     	  '#
**DF%
\\#++,,-9
./13 3 Ir   )r   
__future__r   r   r   r"   googlecloudsdk.callioper   googlecloudsdk.corecore_exceptionsr   Errorr   r   r   r   r   r   r*   r   r   r   <module>r0      sw    5 &  ' 	 . =C H?+@+@ HJ?+@+@ JdO$9$9 d*?r   