2
# sha2.rb - defines Digest::SHA2 class which wraps up the SHA256,
3
# SHA384, and SHA512 classes.
5
# Copyright (c) 2006 Akinori MUSHA <knu@iDaemons.org>
7
# All rights reserved. You can redistribute and/or modify it under the same
10
# $Id: sha2.rb 11708 2007-02-12 23:01:19Z shyouhei $
16
# A meta digest provider class for SHA256, SHA384 and SHA512.
18
class SHA2 < Digest::Class
20
# Digest::SHA2.new(bitlen = 256) -> digest_obj
22
# Creates a new SHA2 hash object with a given bit length.
23
def initialize(bitlen = 256)
26
@sha2 = Digest::SHA256.new
28
@sha2 = Digest::SHA384.new
30
@sha2 = Digest::SHA512.new
32
raise ArgumentError, "unsupported bit length: %s" % bitlen.inspect
64
def initialize_copy(other)
65
@sha2 = other.instance_eval { @sha2.clone }
70
"#<%s:%d %s>" % [self.class.name, @bitlen, hexdigest]