Class: COSE::Algorithm::HMAC
Constant Summary collapse
- BYTE_LENGTH =
8
Instance Attribute Summary collapse
-
#hash_function ⇒ Object
readonly
Returns the value of attribute hash_function.
-
#tag_length ⇒ Object
readonly
Returns the value of attribute tag_length.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(*args, hash_function:, tag_length:) ⇒ HMAC
constructor
A new instance of HMAC.
- #mac(key, to_be_signed) ⇒ Object
Constructor Details
#initialize(*args, hash_function:, tag_length:) ⇒ HMAC
Returns a new instance of HMAC.
13 14 15 16 17 18 |
# File 'lib/cose/algorithm/hmac.rb', line 13 def initialize(*args, hash_function:, tag_length:) super(*args) @hash_function = hash_function @tag_length = tag_length end |
Instance Attribute Details
#hash_function ⇒ Object (readonly)
Returns the value of attribute hash_function.
11 12 13 |
# File 'lib/cose/algorithm/hmac.rb', line 11 def hash_function @hash_function end |
#tag_length ⇒ Object (readonly)
Returns the value of attribute tag_length.
11 12 13 |
# File 'lib/cose/algorithm/hmac.rb', line 11 def tag_length @tag_length end |
Instance Method Details
#mac(key, to_be_signed) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/cose/algorithm/hmac.rb', line 20 def mac(key, to_be_signed) mac = OpenSSL::HMAC.digest(hash_function, key, to_be_signed) if tag_bytesize && tag_bytesize < mac.bytesize mac.byteslice(0, tag_bytesize) else mac end end |