Module: JsonWebToken::Algorithm::Hmac

Extended by:
Common
Defined in:
lib/json_web_token/algorithm/hmac.rb

Constant Summary

Constants included from Common

Common::SHA_BITS

Class Method Summary collapse

Methods included from Common

digest_new, validate_key, validate_sha_bits

Class Method Details

.signed(sha_bits, key, data) ⇒ Object



12
13
14
15
# File 'lib/json_web_token/algorithm/hmac.rb', line 12

def signed(sha_bits, key, data)
  validate_key(key, sha_bits)
  OpenSSL::HMAC.digest(digest_new(sha_bits), key, data)
end

.verified?(mac, sha_bits, key, data) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/json_web_token/algorithm/hmac.rb', line 17

def verified?(mac, sha_bits, key, data)
  validate_key(key, sha_bits)
  Util.constant_time_compare(mac, signed(sha_bits, key, data))
end