Module: JWT::Algos::HmacRbNaCl

Defined in:
lib/jwt/jwa/hmac_rbnacl.rb

Constant Summary collapse

MAPPING =
{ 'HS512256' => ::RbNaCl::HMAC::SHA512256 }.freeze
SUPPORTED =
MAPPING.keys

Class Method Summary collapse

Class Method Details

.sign(algorithm, msg, key) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/jwt/jwa/hmac_rbnacl.rb', line 9

def sign(algorithm, msg, key)
  Deprecations.warning("The use of the algorithm #{algorithm} is deprecated and will be removed in the next major version of ruby-jwt")
  if (hmac = resolve_algorithm(algorithm))
    hmac.auth(key_for_rbnacl(hmac, key).encode('binary'), msg.encode('binary'))
  else
    Hmac.sign(algorithm, msg, key)
  end
end

.verify(algorithm, key, signing_input, signature) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/jwt/jwa/hmac_rbnacl.rb', line 18

def verify(algorithm, key, signing_input, signature)
  Deprecations.warning("The use of the algorithm #{algorithm} is deprecated and will be removed in the next major version of ruby-jwt")
  if (hmac = resolve_algorithm(algorithm))
    hmac.verify(key_for_rbnacl(hmac, key).encode('binary'), signature.encode('binary'), signing_input.encode('binary'))
  else
    Hmac.verify(algorithm, key, signing_input, signature)
  end
rescue ::RbNaCl::BadAuthenticatorError, ::RbNaCl::LengthError
  false
end