123456789_123456789_123456789_123456789_123456789_

Class: Digest::Class

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Instance
Inherits: Object
Defined in: ext/digest/digest.c,
ext/digest/digest.c,
ext/digest/bubblebabble/bubblebabble.c,
ext/digest/lib/digest.rb

Overview

This module stands as a base class for digest implementation classes.

Class Method Summary

Instance Method Summary

Instance - Included

#<<

Updates the digest using a given string and returns self.

#==

If a string is given, checks whether it is equal to the hex-encoded hash value of the digest object.

#base64digest

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

#base64digest!

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

#block_length

Returns the block length of the digest.

#bubblebabble

Returns the resulting hash value in a Bubblebabble encoded form.

#digest

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

#digest!

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

#digest_length

Returns the length of the hash value of the digest.

#file

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

#hexdigest

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

#hexdigest!

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

#inspect

Creates a printable version of the digest object.

#length

Returns digest_obj.digest_length().

#new

Returns a new, initialized copy of the digest object.

#reset

Resets the digest to the initial state and returns self.

#size

Alias for Instance#length.

#to_s

Returns digest_obj.hexdigest().

#update

Alias for Instance#<<.

#finish

Finishes the digest and returns the resulting hash value.

Class Method Details

.base64digest(str, *args)

Returns the base64 encoded hash value of a given string. The return value is properly padded with '=' and contains no line feeds.

[ GitHub ]

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

def self.base64digest(str, *args)
  [digest(str, *args)].pack('m0')
end

.digest(string, *parameters) ⇒ hash_string

Returns the hash value of a given string. This is equivalent to Class.new(*parameters).digest(string), where extra parameters, if any, are passed through to the constructor and the string is passed to #digest().

.file(name, *args)

Creates a digest object and reads a given file, name. Optional arguments are passed to the constructor of the digest class.

p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
# => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
[ GitHub ]

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

def self.file(name, *args)
  new(*args).file(name)
end

.hexdigest(string[, ...]) ⇒ hash_string

Returns the hex-encoded hash value of a given string. This is almost equivalent to ::Digest.hexencode(Digest::Class.new(*parameters).digest(string)).