Sha256: 15aee603eb5002b37e56435201445a80acb00b260c6b976adfbf3d3cde70fe6a

Contents?: true

Size: 741 Bytes

Versions: 4

Compression:

Stored size: 741 Bytes

Contents

# frozen_string_literal: true

require_relative 'jwk/rsa'
require_relative 'jwk/key_finder'

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

    class << self
      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

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

      alias new create_from
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jwt-2.2.2 lib/jwt/jwk.rb
jwt-2.2.1 lib/jwt/jwk.rb
jwt-2.2.0 lib/jwt/jwk.rb
jwt-2.2.0.pre.beta.0 lib/jwt/jwk.rb