Module: JWT::JWK

Defined in:
lib/jwt/jwk.rb,
lib/jwt/jwk/rsa.rb,
lib/jwt/jwk/key_finder.rb

Defined Under Namespace

Classes: KeyFinder, RSA

Constant Summary collapse

MAPPINGS =
{
  'RSA' => ::JWT::JWK::RSA,
  OpenSSL::PKey::RSA => ::JWT::JWK::RSA
}.freeze

Class Method Summary collapse

Class Method Details

.create_from(keypair) ⇒ Object Also known as: new


22
23
24
25
26
# File 'lib/jwt/jwk.rb', line 22

def create_from(keypair)
  MAPPINGS.fetch(keypair.class) do |klass|
    raise JWT::JWKError, "Cannot create JWK from a #{klass.name}"
  end.new(keypair)
end

.import(jwk_data) ⇒ Object

Raises:


14
15
16
17
18
19
20
# File 'lib/jwt/jwk.rb', line 14

def import(jwk_data)
  raise JWT::JWKError, 'Key type (kty) not provided' unless jwk_data[:kty]

  MAPPINGS.fetch(jwk_data[:kty].to_s) do |kty|
    raise JWT::JWKError, "Key type #{kty} not supported"
  end.import(jwk_data)
end