Class: CryptoToolchain::BlackBoxes::SHA1Mac
- Defined in:
- lib/crypto_toolchain/black_boxes/sha1_mac.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key: Random.new.bytes(16)) ⇒ SHA1Mac
constructor
A new instance of SHA1Mac.
- #mac(str) ⇒ Object
- #valid?(message:, mac:) ⇒ Boolean
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
#key ⇒ Object (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
15 16 17 |
# File 'lib/crypto_toolchain/black_boxes/sha1_mac.rb', line 15 def valid?(message: , mac: ) self.mac() == mac end |