Class: SHA3::Digest

Inherits:
Digest::Class
  • Object
show all
Defined in:
lib/sha3/doc.rb

Overview

Note:

SHA3::Digest class provides a four sub-classes for the available hash bit lengths (types). You can instantiate a new instance of Digest sub-class for a given type using the following sub-classes:

SHA3::Digest::SHA224([data])
SHA3::Digest::SHA256([data])
SHA3::Digest::SHA384([data])
SHA3::Digest::SHA512([data])

The [data] parameter is optional.

A sub-class of (MRI Ruby based) Digest::Class, it implements SHA3 (Keccak) digest algorithm.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, data) ⇒ Digest

Creates a Digest instance based on given hash bit length (type).

Examples:

digest = SHA3::Digest.new      # => Defaults to 256 bits
digest = SHA3::Digest.new(224) # => Initialize a new 224 bit digest instance
digest = SHA3::Digest::SHA224  # => An alternate method for creating a digest class with 224 bit hash bit length

Parameters:

  • type (Number, Symbol)

    optional parameter used to set hash bit length (type). Valid options are:

      Number: 224, 256, 384, or 512
    Symobols: :sha224, :sha256, :sha384, or :sha512
    

    Default value: 256 (bits)

  • data (String)

    optional parameter used to update initial instance state. #



35
36
37
# File 'lib/sha3/doc.rb', line 35

def initialize(type, data)
  # See function: c_digest_init(...) in ext/sha3/_digest.c
end

Class Method Details

.digest(type, data) ⇒ String

Returns computed hash value for given hash type, and data in bytes.

Examples:

SHA3::Digest.digest(256, 'compute me, please')
SHA3::Digest::SHA256.digest('compute me, please') # => Alternate syntax

Parameters:

  • type (Number, Symbol)

    See #initialize for valid type values.

  • data (String)

    data to compute hash value

Returns:

  • (String)

    computed hash in bytes



116
# File 'lib/sha3/doc.rb', line 116

def self.digest(type, data); end

.hexdigest(type, data) ⇒ String

Returns computed hash value for given hash type, and data in hex (string).

Examples:

SHA3::Digest.hexdigest(256, 'compute me, please')
SHA3::Digest::SHA256.hexdigest('compute me, please') # => Alternate syntax

Parameters:

  • type (Number, Symbol)

    See #initialize for valid type values.

  • data (String)

    data to compute hash value

Returns:

  • (String)

    computed hash as hex-encoded string



104
# File 'lib/sha3/doc.rb', line 104

def self.hexdigest(type, data); end

Instance Method Details

#block_lengthNumber

Returns digest block length in bytes.

Examples:

digest = SHA3::Digest::SHA384.new
digest.block_length # Result => 104

Returns:

  • (Number)

    digest block length in bytes.



83
84
85
# File 'lib/sha3/doc.rb', line 83

def block_length
  # See function: c_digest_block_length(...) in ext/sha3/_digest.c
end

#lengthNumber

Returns message digest length in bytes.

Examples:

digest = SHA3::Digest::SHA256.new
digest.length # Result => 32 (or 256 bits)

Returns:

  • (Number)

    message length in bytes.



72
73
74
# File 'lib/sha3/doc.rb', line 72

def length
  # See function: c_digest_length(...) in ext/sha3/_digest.c
end

#nameString

Returns name of initialized digest

Returns:

  • (String)

    name



90
91
92
# File 'lib/sha3/doc.rb', line 90

def name
  # See function: c_digest_name(...) in ext/sha3/_digest.c
end

#resetDigest

Resets the Digest object to initial state, abandoning computed data.

Returns:



61
62
63
# File 'lib/sha3/doc.rb', line 61

def reset
  # See function: c_digest_reset(...) in ext/sha3/_digest.c
end

#update(data) ⇒ Digest Also known as: <<

Updates, and recalculates Message Digest (state) with given data. If a message digest is to be computed from several subsequent sources, then each may be passed individually to the Digest instance.

Examples:

digest = SHA3::Digest::SHA256.new
digest.update('hash me')
digest.update('me too')

Parameters:

  • data (String)

    data to compute

Returns:



51
52
53
# File 'lib/sha3/doc.rb', line 51

def update(data)
  # See function: c_digest_update(...) in ext/sha3/_digest.c
end