<commit_before>require 'openssl'

module Aws
  module Plugins

    # @seahorse.client.option [Boolean] :verify_checksums (true)
    #   When `true` MD5 checksums will be computed for messages sent to
    #   an SQS queue and matched against MD5 checksums returned by Amazon SQS.
    #   `Aws::Errors::Checksum` errors are raised for cases where checksums do
    #   not match.
    class SQSMd5s < Seahorse::Client::Plugin
      OPERATIONS_TO_VERIFY = [:send_message, :send_message_batch]

      # @api private
      class Handler < Seahorse::Client::Handler
        def call(context)
          @handler.call(context).on_success do |response|
            case context.operation_name
            when :send_message
              validate_send_message(context, response)
            when :send_message_batch
              validate_send_message_batch(context, response)
            end
          end
        end

        private

        TRANSPORT_TYPE_ENCODINGS = {
          'String' => 1,
          'Binary' => 2,
          'Number' => 1
        }

        DATA_TYPE = /\A(String|Binary|Number)(\..+)?\z/

        NORMALIZED_ENCODING = Encoding::UTF_8

        def validate_send_message(context, response)
          body = context.params[:message_body]
          attributes = context.params[:message_attributes]
          validate_single_message(body, attributes, response)
        end

        def validate_send_message_batch(context, response)
          context.params[:entries].each do |entry|
            id = entry[:id]
            body = entry[:message_body]
            attributes = entry[:message_attributes]
            message_response = response.successful.select { |r| r.id == id }[0]
            unless message_response.nil?
              validate_single_message(body, attributes, message_response)
            end
          end
        end

        def validate_single_message(body, attributes, response)
          validate_body(body, response)
          validate_attributes(attributes, response) unless attributes.nil?
        end

        def validate_body(body, response)
          calculated_md5 = md5_of_message_body(body)
          returned_md5 = response.md5_of_message_body
          if calculated_md5 != returned_md5
            error_message =  mismatch_error_message(
              'message body',
              calculated_md5,
              returned_md5,
              response)
            raise Aws::Errors::ChecksumError, error_message
          end
        end

        def validate_attributes(attributes, response)
          calculated_md5 = md5_of_message_attributes(attributes)
          returned_md5 = response.md5_of_message_attributes
          if returned_md5 != calculated_md5
            error_message =  mismatch_error_message(
              'message atributes',
              calculated_md5,
              returned_md5,
              response)
            raise Aws::Errors::ChecksumError, error_message
          end
        end

        def md5_of_message_body(message_body)
          OpenSSL::Digest::MD5.hexdigest(message_body)
        end<commit_msg>Fix typo<commit_after>require 'openssl'

module Aws
  module Plugins

    # @seahorse.client.option [Boolean] :verify_checksums (true)
    #   When `true` MD5 checksums will be computed for messages sent to
    #   an SQS queue and matched against MD5 checksums returned by Amazon SQS.
    #   `Aws::Errors::Checksum` errors are raised for cases where checksums do
    #   not match.
    class SQSMd5s < Seahorse::Client::Plugin
      OPERATIONS_TO_VERIFY = [:send_message, :send_message_batch]

      # @api private
      class Handler < Seahorse::Client::Handler
        def call(context)
          @handler.call(context).on_success do |response|
            case context.operation_name
            when :send_message
              validate_send_message(context, response)
            when :send_message_batch
              validate_send_message_batch(context, response)
            end
          end
        end

        private

        TRANSPORT_TYPE_ENCODINGS = {
          'String' => 1,
          'Binary' => 2,
          'Number' => 1
        }

        DATA_TYPE = /\A(String|Binary|Number)(\..+)?\z/

        NORMALIZED_ENCODING = Encoding::UTF_8

        def validate_send_message(context, response)
          body = context.params[:message_body]
          attributes = context.params[:message_attributes]
          validate_single_message(body, attributes, response)
        end

        def validate_send_message_batch(context, response)
          context.params[:entries].each do |entry|
            id = entry[:id]
            body = entry[:message_body]
            attributes = entry[:message_attributes]
            message_response = response.successful.select { |r| r.id == id }[0]
            unless message_response.nil?
              validate_single_message(body, attributes, message_response)
            end
          end
        end

        def validate_single_message(body, attributes, response)
          validate_body(body, response)
          validate_attributes(attributes, response) unless attributes.nil?
        end

        def validate_body(body, response)
          calculated_md5 = md5_of_message_body(body)
          returned_md5 = response.md5_of_message_body
          if calculated_md5 != returned_md5
            error_message =  mismatch_error_message(
              'message body',
              calculated_md5,
              returned_md5,
              response)
            raise Aws::Errors::ChecksumError, error_message
          end
        end

        def validate_attributes(attributes, response)
          calculated_md5 = md5_of_message_attributes(attributes)
          returned_md5 = response.md5_of_message_attributes
          if returned_md5 != calculated_md5
            error_message =  mismatch_error_message(
              'message attributes',
              calculated_md5,
              returned_md5,
              response)
            raise Aws::Errors::ChecksumError, error_message
          end
        end

        def md5_of_message_body(message_body)
          OpenSSL::Digest::MD5.hexdigest(message_body)
        end
{'fraction_non_alphanumeric': 0.07242159715486583, 'fraction_numerical': 0.008406078241189783, 'mean_word_length': 2.1215943491422804, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3131705', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1655, 'n_words': 362}