module JWT::JWK

Public Class Methods

classes() click to toggle source
# File lib/jwt/jwk.rb, line 23
def classes
  @mappings = nil # reset the cached mappings
  @classes ||= []
end
create_from(keypair) click to toggle source
# File lib/jwt/jwk.rb, line 17
def create_from(keypair)
  mappings.fetch(keypair.class) do |klass|
    raise JWT::JWKError, "Cannot create JWK from a #{klass.name}"
  end.new(keypair)
end
Also aliased as: new
import(jwk_data) click to toggle source
# File lib/jwt/jwk.rb, line 8
def import(jwk_data)
  jwk_kty = jwk_data[:kty] || jwk_data['kty']
  raise JWT::JWKError, 'Key type (kty) not provided' unless jwk_kty

  mappings.fetch(jwk_kty.to_s) do |kty|
    raise JWT::JWKError, "Key type #{kty} not supported"
  end.import(jwk_data)
end
new(keypair)
Alias for: create_from

Private Class Methods

generate_mappings() click to toggle source
# File lib/jwt/jwk.rb, line 36
def generate_mappings
  classes.each_with_object({}) do |klass, hash|
    next unless klass.const_defined?('KTYS')
    Array(klass::KTYS).each do |kty|
      hash[kty] = klass
    end
  end
end
mappings() click to toggle source
# File lib/jwt/jwk.rb, line 32
def mappings
  @mappings ||= generate_mappings
end