class Aws::Plugins::S3SseCpk::Handler

def base64(str)

def base64(str)
  Base64.encode64(str).strip
end

def call(context)

def call(context)
  compute_key_md5(context)
  @handler.call(context)
end

def compute_key_md5(context)

def compute_key_md5(context)
  params = context.params
  if key = params[:sse_customer_key]
    require_https(context)
    params[:sse_customer_key] = base64(key)
    params[:sse_customer_key_md5] = base64(md5(key))
  end
  if key = params[:copy_source_sse_customer_key]
    require_https(context)
    params[:copy_source_sse_customer_key] = base64(key)
    params[:copy_source_sse_customer_key_md5] = base64(md5(key))
  end
end

def md5(str)

def md5(str)
  OpenSSL::Digest::MD5.digest(str)
end

def require_https(context)

def require_https(context)
  unless URI::HTTPS === context.config.endpoint
    msg = <<-MSG.strip.gsub("\n", ' ')
      Attempting to send customer-provided-keys for S3
      server-side-encryption over HTTP; Please configure a HTTPS
      endpoint. If you are attempting to use a test endpoint,
      you can disable this check via `:require_https_for_sse_cpk`
    MSG
    raise ArgumentError, msg
  end
end