Class: Stribog::CreateHash

Inherits:
Object
  • Object
show all
Defined in:
lib/stribog/create_hash.rb

Overview

CreateHash

Class, which creates digests.

Author:

  • WildDima

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, transformation = :from_hex, vector = Stribog.vector) ⇒ CreateHash

Returns a new instance of CreateHash.



32
33
34
35
36
# File 'lib/stribog/create_hash.rb', line 32

def initialize(message, transformation = :from_hex, vector = Stribog.vector)
  @message = message
  @transformation = transformation
  @vector = vector
end

Instance Attribute Details

#digest_lengthFixnum (readonly)

Length of digest. Should be equal to 256 or 512.

Examples:

digest.digest_length

Returns:

  • (Fixnum)

    binary representation of digest



21
22
23
# File 'lib/stribog/create_hash.rb', line 21

def digest_length
  @digest_length
end

#messageString (readonly)

Original message

Examples:

hash.message

Returns:

  • (String)

    contains original message



13
14
15
# File 'lib/stribog/create_hash.rb', line 13

def message
  @message
end

#message_vectorBinaryVector (readonly)

Contain message as instance of BinaryVector

Examples:

digest.message_vector

Returns:

  • (BinaryVector)

    binary representation of message



29
30
31
# File 'lib/stribog/create_hash.rb', line 29

def message_vector
  @message_vector
end

#vectorObject (readonly)

Returns the value of attribute vector.



30
31
32
# File 'lib/stribog/create_hash.rb', line 30

def vector
  @vector
end

Instance Method Details

#call(digest_length = HASH_LENGTH) ⇒ Object

Create digest of #message. Default equal to 512.

Examples:

Stribog::CreateHash.new('ruby').call(256)
Stribog::CreateHash.new('ruby').call(512)

Author:

  • WildDima



44
45
46
47
48
49
50
51
52
53
# File 'lib/stribog/create_hash.rb', line 44

def call(digest_length = HASH_LENGTH)
  @digest_length = digest_length
  return_hash(
    Stage::Final.new(
      Stage::Compression.new(
        Stage::Initial.new(self)
      )
    ).call
  )
end