Class: Datadog::Core::Remote::Configuration::Digest

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/remote/configuration/digest.rb

Overview

Stores and validates different cryptographic hash functions

Defined Under Namespace

Classes: InvalidHashTypeError

Constant Summary collapse

DIGEST_CHUNK =
1024

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, hexdigest) ⇒ Digest

Returns a new instance of Digest.



50
51
52
53
# File 'lib/datadog/core/remote/configuration/digest.rb', line 50

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

Instance Attribute Details

#hexdigestObject (readonly)

Returns the value of attribute hexdigest.



25
26
27
# File 'lib/datadog/core/remote/configuration/digest.rb', line 25

def hexdigest
  @hexdigest
end

#typeObject (readonly)

Returns the value of attribute type.



25
26
27
# File 'lib/datadog/core/remote/configuration/digest.rb', line 25

def type
  @type
end

Class Method Details

.hexdigest(type, data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datadog/core/remote/configuration/digest.rb', line 30

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

Instance Method Details

#check(content) ⇒ Object



55
56
57
# File 'lib/datadog/core/remote/configuration/digest.rb', line 55

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