Module: JsonWebToken::Jwa

Defined in:
lib/json_web_token/jwa.rb

Constant Summary collapse

ALGORITHMS =
/(HS|RS|ES)(256|384|512)?/i
ALG_LENGTH =
5

Class Method Summary collapse

Class Method Details

.signed(algorithm, key, data) ⇒ Object



13
14
15
16
# File 'lib/json_web_token/jwa.rb', line 13

def signed(algorithm, key, data)
  alg = validated_alg(algorithm)
  alg[:constant].signed(alg[:sha_bits], key, data)
end

.validated_constant(str) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/json_web_token/jwa.rb', line 39

def validated_constant(str)
  case str
  when 'hs' then Algorithm::Hmac
  when 'rs' then Algorithm::Rsa
  when 'es' then Algorithm::Ecdsa
  else fail('Unsupported algorithm')
  end
end

.verified?(signature, algorithm, key, data) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/json_web_token/jwa.rb', line 18

def verified?(signature, algorithm, key, data)
  alg = validated_alg(algorithm)
  alg[:constant].verified?(signature, alg[:sha_bits], key, data)
end