Class: Digest::SHA2
Overview
A meta digest provider class for SHA256, SHA384 and SHA512.
Instance Method Summary collapse
- #block_length ⇒ Object
- #digest_length ⇒ Object
-
#initialize(bitlen = 256) ⇒ SHA2
constructor
call-seq: Digest::SHA2.new(bitlen = 256) -> digest_obj.
-
#initialize_copy(other) ⇒ Object
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
-
#reset ⇒ Object
:nodoc:.
-
#update(str) ⇒ Object
(also: #<<)
:nodoc:.
Methods inherited from Class
Methods included from Instance
#==, #digest, #digest!, #file, #hexdigest, #hexdigest!, #length, #new, #size, #to_s
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.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'sha2/lib/sha2.rb', line 23 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_length ⇒ Object
55 56 57 |
# File 'sha2/lib/sha2.rb', line 55 def block_length @sha2.block_length end |
#digest_length ⇒ Object
59 60 61 |
# File 'sha2/lib/sha2.rb', line 59 def digest_length @sha2.digest_length end |
#initialize_copy(other) ⇒ Object
:nodoc:
64 65 66 |
# File 'sha2/lib/sha2.rb', line 64 def initialize_copy(other) @sha2 = other.instance_eval { @sha2.clone } end |
#inspect ⇒ Object
:nodoc:
69 70 71 |
# File 'sha2/lib/sha2.rb', line 69 def inspect "#<%s:%d %s>" % [self.class.name, @bitlen, hexdigest] end |
#reset ⇒ Object
:nodoc:
38 39 40 41 |
# File 'sha2/lib/sha2.rb', line 38 def reset @sha2.reset self end |
#update(str) ⇒ Object Also known as: <<
:nodoc:
44 45 46 47 |
# File 'sha2/lib/sha2.rb', line 44 def update(str) @sha2.update(str) self end |