Sha256: 1a4f64ff547ce67aa3ccdc0986b571579e7a6964e857c8c47c2e5f23b5fdd18f

Contents?: true

Size: 1.47 KB

Versions: 35

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

require 'digest'

module Datadog
  module Core
    module Remote
      class Configuration
        # Represent a list of Configuration::Digest
        class DigestList < Array
          class << self
            def parse(hash)
              new.concat(hash.map { |type, hexdigest| Digest.new(type, hexdigest) })
            end
          end

          def check(content)
            map { |digest| digest.check(content) }.reduce(:&)
          end
        end

        # Stores and validates different cryptographic hash functions
        class Digest
          class InvalidHashTypeError < StandardError; end
          attr_reader :type, :hexdigest

          DIGEST_CHUNK = 1024

          class << self
            def hexdigest(type, data)
              d = case type
                  when :sha256
                    ::Digest::SHA256.new
                  when :sha512
                    ::Digest::SHA512.new
                  else
                    raise InvalidHashTypeError, type
                  end

              while (buf = data.read(DIGEST_CHUNK))
                d.update(buf)
              end

              d.hexdigest
            ensure
              data.rewind
            end
          end

          def initialize(type, hexdigest)
            @type = type.to_sym
            @hexdigest = hexdigest
          end

          def check(content)
            content.hexdigest(@type) == hexdigest
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
datadog-2.9.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.8.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.7.1 lib/datadog/core/remote/configuration/digest.rb
datadog-2.7.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.6.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.5.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.4.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.3.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.2.0 lib/datadog/core/remote/configuration/digest.rb
ddtrace-1.23.3 lib/datadog/core/remote/configuration/digest.rb
ddtrace-1.23.2 lib/datadog/core/remote/configuration/digest.rb
datadog-2.1.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.0.0 lib/datadog/core/remote/configuration/digest.rb
ddtrace-1.23.1 lib/datadog/core/remote/configuration/digest.rb
datadog-2.0.0.beta2 lib/datadog/core/remote/configuration/digest.rb
ddtrace-1.22.0 lib/datadog/core/remote/configuration/digest.rb
datadog-2.0.0.beta1 lib/datadog/core/remote/configuration/digest.rb
ddtrace-1.21.1 lib/datadog/core/remote/configuration/digest.rb
ddtrace-1.21.0 lib/datadog/core/remote/configuration/digest.rb
ddtrace-1.20.0 lib/datadog/core/remote/configuration/digest.rb