Class: CryptoToolchain::BlackBoxes::SHA1Mac

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/black_boxes/sha1_mac.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: Random.new.bytes(16)) ⇒ SHA1Mac

Returns a new instance of SHA1Mac.



6
7
8
# File 'lib/crypto_toolchain/black_boxes/sha1_mac.rb', line 6

def initialize(key: Random.new.bytes(16))
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/crypto_toolchain/black_boxes/sha1_mac.rb', line 4

def key
  @key
end

Instance Method Details

#mac(str) ⇒ Object



10
11
12
13
# File 'lib/crypto_toolchain/black_boxes/sha1_mac.rb', line 10

def mac(str)
  concat = key + str
  CryptoToolchain::Utilities::SHA1.hexdigest(concat)
end

#valid?(message:, mac:) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/crypto_toolchain/black_boxes/sha1_mac.rb', line 15

def valid?(message: , mac: )
  self.mac(message) == mac
end