# module Puppet::Util::Checksums

A stand-alone module for calculating checksums in a generic way.

### Public Instance Methods

checksum?(string) click to toggle source

Is the provided string a checksum?

    # File lib/puppet/util/checksums.rb, line 14
    def checksum?(string)
      string =~ /^\{(\w{3,5})\}\S+/
    end

ctime(content) click to toggle source

    # File lib/puppet/util/checksums.rb, line 110
    def ctime(content)
      ""
    end

ctime_file(filename) click to toggle source

Return the :ctime of a file.

    # File lib/puppet/util/checksums.rb, line 104
    def ctime_file(filename)
      File.stat(filename).send(:ctime)
    end

ctime_stream()
Alias for: mtime_stream
md5(content) click to toggle source

Calculate a checksum using Digest::MD5.

    # File lib/puppet/util/checksums.rb, line 29
    def md5(content)
      Digest::MD5.hexdigest(content)
    end

md5_file(filename, lite = false) click to toggle source

Calculate a checksum of a file’s content using Digest::MD5.

    # File lib/puppet/util/checksums.rb, line 39
    def md5_file(filename, lite = false)
      digest = Digest::MD5.new
      checksum_file(digest, filename,  lite)
    end

md5_stream() { |digest| ... } click to toggle source

    # File lib/puppet/util/checksums.rb, line 49
    def md5_stream(&block)
      digest = Digest::MD5.new
      yield digest
      digest.hexdigest
    end

Also aliased as: md5lite_stream
md5lite(content) click to toggle source

Calculate a checksum of the first 500 chars of the content using Digest::MD5.

    # File lib/puppet/util/checksums.rb, line 34
    def md5lite(content)
      md5(content[0..511])
    end

md5lite_file(filename) click to toggle source

Calculate a checksum of the first 500 chars of a file’s content using Digest::MD5.

    # File lib/puppet/util/checksums.rb, line 45
    def md5lite_file(filename)
      md5_file(filename, true)
    end

md5lite_stream(&block)
Alias for: md5_stream
mtime(content) click to toggle source

    # File lib/puppet/util/checksums.rb, line 70
    def mtime(content)
      ""
    end

mtime_file(filename) click to toggle source

Return the :mtime timestamp of a file.

    # File lib/puppet/util/checksums.rb, line 58
    def mtime_file(filename)
      File.stat(filename).send(:mtime)
    end

mtime_stream() { |noop_digest| ... } click to toggle source

by definition this doesn’t exist but we still need to execute the block given

    # File lib/puppet/util/checksums.rb, line 64
    def mtime_stream
      noop_digest = FakeChecksum.new
      yield noop_digest
      nil
    end

Also aliased as: ctime_stream
none(content) click to toggle source

    # File lib/puppet/util/checksums.rb, line 125
    def none(content)
      ""
    end

none_file(filename) click to toggle source

Return a “no checksum”

    # File lib/puppet/util/checksums.rb, line 115
    def none_file(filename)
      ""
    end

none_stream() { |noop_digest| ... } click to toggle source

    # File lib/puppet/util/checksums.rb, line 119
    def none_stream
      noop_digest = FakeChecksum.new
      yield noop_digest
      ""
    end

sha1(content) click to toggle source

Calculate a checksum using Digest::SHA1.

    # File lib/puppet/util/checksums.rb, line 75
    def sha1(content)
      Digest::SHA1.hexdigest(content)
    end

sha1_file(filename, lite = false) click to toggle source

Calculate a checksum of a file’s content using Digest::SHA1.

    # File lib/puppet/util/checksums.rb, line 85
    def sha1_file(filename, lite = false)
      digest = Digest::SHA1.new
      checksum_file(digest, filename, lite)
    end

sha1_stream() { |digest| ... } click to toggle source

    # File lib/puppet/util/checksums.rb, line 95
    def sha1_stream
      digest = Digest::SHA1.new
      yield digest
      digest.hexdigest
    end

Also aliased as: sha1lite_stream
sha1lite(content) click to toggle source

Calculate a checksum of the first 500 chars of the content using Digest::SHA1.

    # File lib/puppet/util/checksums.rb, line 80
    def sha1lite(content)
      sha1(content[0..511])
    end

sha1lite_file(filename) click to toggle source

Calculate a checksum of the first 500 chars of a file’s content using Digest::SHA1.

    # File lib/puppet/util/checksums.rb, line 91
    def sha1lite_file(filename)
      sha1_file(filename, true)
    end

sha1lite_stream()
Alias for: sha1_stream
sumdata(checksum) click to toggle source

Strip the checksum type from an existing checksum

    # File lib/puppet/util/checksums.rb, line 19
    def sumdata(checksum)
      checksum =~ /^\{(\w+)\}(.+)/ ? $2 : nil
    end

sumtype(checksum) click to toggle source

Strip the checksum type from an existing checksum

    # File lib/puppet/util/checksums.rb, line 24
    def sumtype(checksum)
      checksum =~ /^\{(\w+)\}/ ? $1 : nil
    end