Class: Digest::SHA2

Inherits:
Class show all
Defined in:
lib/extensions/digest-sha2/sha2/sha2.rb

Overview

A meta digest provider class for SHA256, SHA384 and SHA512.

Instance Method Summary collapse

Methods inherited from Class

file

Constructor Details

#initialize(bitlen = 256) ⇒ SHA2

call-seq:

Digest::SHA2.new(bitlen = 256) -> digest_obj

Creates a new SHA2 hash object with a given bit length.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/extensions/digest-sha2/sha2/sha2.rb', line 24

def initialize(bitlen = 256)
  case bitlen
  when 256
    @sha2 = Digest::SHA256.new
  when 384
    @sha2 = Digest::SHA384.new
  when 512
    @sha2 = Digest::SHA512.new
  else
    raise ArgumentError, "unsupported bit length: %s" % bitlen.inspect
  end
  @bitlen = bitlen
end

Instance Method Details

#block_lengthObject



56
57
58
# File 'lib/extensions/digest-sha2/sha2/sha2.rb', line 56

def block_length
  @sha2.block_length
end

#digest_lengthObject



60
61
62
# File 'lib/extensions/digest-sha2/sha2/sha2.rb', line 60

def digest_length
  @sha2.digest_length
end

#initialize_copy(other) ⇒ Object

:nodoc:



65
66
67
# File 'lib/extensions/digest-sha2/sha2/sha2.rb', line 65

def initialize_copy(other)
  @sha2 = other.instance_eval { @sha2.clone }
end

#inspectObject

:nodoc:



70
71
72
# File 'lib/extensions/digest-sha2/sha2/sha2.rb', line 70

def inspect
  "#<%s:%d %s>" % [self.class.name, @bitlen, hexdigest]
end

#resetObject

:nodoc:



39
40
41
42
# File 'lib/extensions/digest-sha2/sha2/sha2.rb', line 39

def reset
  @sha2.reset
  self
end

#update(str) ⇒ Object Also known as: <<

:nodoc:



45
46
47
48
# File 'lib/extensions/digest-sha2/sha2/sha2.rb', line 45

def update(str)
  @sha2.update(str)
  self
end