123456789_123456789_123456789_123456789_123456789_

Module: Digest::Instance

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: ext/digest/digest.c,
ext/digest/bubblebabble/bubblebabble.c,
ext/digest/lib/digest.rb

Overview

This module provides instance methods for a digest implementation object to calculate message digest values.

Instance Method Summary

Instance Method Details

#update(string) ⇒ digest_obj #<<(string) ⇒ digest_obj
Also known as: #update

Updates the digest using a given string and returns self.

The update() method and the left-shift operator are overridden by each implementation subclass. (One should be an alias for the other)

#==(another_digest_obj) ⇒ Boolean #==(string) ⇒ Boolean

If a string is given, checks whether it is equal to the hex-encoded hash value of the digest object. If another digest instance is given, checks whether they have the same hash value. Otherwise returns false.

#base64digest(str = nil)

If none is given, returns the resulting hash value of the digest in a base64 encoded form, keeping the digest's state.

If a string is given, returns the hash value for the given string in a base64 encoded form, resetting the digest to the initial state before and after the process.

In either case, the return value is properly padded with '=' and contains no line feeds.

[ GitHub ]

  
# File 'ext/digest/lib/digest.rb', line 68

def base64digest(str = nil)
  [str ? digest(str) : digest].pack('m0')
end

#base64digest!

Returns the resulting hash value and resets the digest to the initial state.

[ GitHub ]

  
# File 'ext/digest/lib/digest.rb', line 74

def base64digest!
  [digest!].pack('m0')
end

#block_lengthInteger

Returns the block length of the digest.

This method is overridden by each implementation subclass.

#bubblebabblehash_string

Returns the resulting hash value in a Bubblebabble encoded form.

#digestString #digest(string) ⇒ String

If none is given, returns the resulting hash value of the digest, keeping the digest's state.

If a string is given, returns the hash value for the given string, resetting the digest to the initial state before and after the process.

#digest!String

Returns the resulting hash value and resets the digest to the initial state.

#digest_lengthInteger

Returns the length of the hash value of the digest.

This method should be overridden by each implementation subclass. If not, digest_obj.digest().length() is returned.

#file(name)

Updates the digest with the contents of a given file name and returns self.

[ GitHub ]

  
# File 'ext/digest/lib/digest.rb', line 49

def file(name)
  File.open(name, "rb") {|f|
    buf = ""
    while f.read(16384, buf)
      update buf
    end
  }
  self
end

#instance_evaldigest_obj (private)

Finishes the digest and returns the resulting hash value.

This method is overridden by each implementation subclass and often made private, because some of those subclasses may leave internal data uninitialized. Do not call this method from outside. Use #digest!() instead, which ensures that internal data be reset for security reasons.

#hexdigestString #hexdigest(string) ⇒ String

If none is given, returns the resulting hash value of the digest in a hex-encoded form, keeping the digest's state.

If a string is given, returns the hash value for the given string in a hex-encoded form, resetting the digest to the initial state before and after the process.

#hexdigest!String

Returns the resulting hash value in a hex-encoded form and resets the digest to the initial state.

#inspectString

Creates a printable version of the digest object.

#lengthInteger #sizeInteger
Also known as: #size

Returns digest_obj.digest_length().

#newanother_digest_obj

Returns a new, initialized copy of the digest object. Equivalent to digest_obj.clone().reset().

#resetdigest_obj

Resets the digest to the initial state and returns self.

This method is overridden by each implementation subclass.

#lengthInteger #sizeInteger

Alias for #length.

#to_sString

Returns digest_obj.hexdigest().

#update(string) ⇒ digest_obj #<<(string) ⇒ digest_obj

Alias for #<<.