class COSE::Algorithm::HMAC

Constants

BYTE_LENGTH

Attributes

hash_function[R]
tag_length[R]

Public Class Methods

new(*args, hash_function:, tag_length:) click to toggle source
Calls superclass method COSE::Algorithm::Base::new
# 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

Public Instance Methods

mac(key, to_be_signed) click to toggle source
# 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

Private Instance Methods

tag_bytesize() click to toggle source
# File lib/cose/algorithm/hmac.rb, line 32
def tag_bytesize
  @tag_bytesize ||=
    if tag_length
      tag_length / BYTE_LENGTH
    end
end