class Aws::Plugins::S3RequestSigner::SigningHandler

def apply_v2_signature(context)

def apply_v2_signature(context)
  Signers::S3.sign(context)
end

def apply_v4_signature(context)

def apply_v4_signature(context)
  Signers::V4.new(
    context.config.credentials, 's3',
    context[:cached_sigv4_region] || context.config.sigv4_region,
  ).sign(context.http_request)
end

def call(context)

def call(context)
  require_credentials(context)
  version = signature_version(context)
  case version
  when /v4/ then apply_v4_signature(context)
  when /s3/ then apply_v2_signature(context)
  else raise "unsupported signature version #{version.inspect}"
  end
  @handler.call(context)
end

def classic_endpoint?(context)

def classic_endpoint?(context)
  context.config.region == 'us-east-1'
end

def classic_sigv(context)

Choose v4 only if using KMS encryptions, which requires v4.
the region name. This makes creating a version 4 signature difficult.
When accessing the classic endpoint, s3.amazonaws.com, we don't know
def classic_sigv(context)
  if kms_encrypted?(context)
    :v4
  else
    :s3
  end
end

def kms_encrypted?(context)

def kms_encrypted?(context)
  context.params[:server_side_encryption] == 'aws:kms'
end

def regional_sigv(context)

def regional_sigv(context)
  # Drop back to older S3 signature version when uploading objects for
  # better performance. This optimization may be removed at some point
  # in favor of always using signature version 4.
  if V2_REGIONS.include?(context.config.region)
    uploading_file?(context) && !kms_encrypted?(context) ? :s3 : :v4
  else
    :v4
  end
end

def signature_version(context)

def signature_version(context)
  context[:cached_signature_version] ||
  context.config.signature_version ||
  version_by_region(context)
end

def uploading_file?(context)

def uploading_file?(context)
  %w(put_object upload_part).include?(context.operation_name) &&
    context.http_request.body.size > 0
end

def version_by_region(context)

def version_by_region(context)
  if classic_endpoint?(context)
    classic_sigv(context)
  else
    regional_sigv(context)
  end
end