Sha256: fa5d05d10b8bfcaff4cd89fc185517d16fbfe2522de3759d52567b571ac6228a

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module JWT
  module JWK
    class KeyBase
      def self.inherited(klass)
        super
        ::JWT::JWK.classes << klass
      end

      def initialize(options, params = {})
        options ||= {}

        @parameters = params.transform_keys(&:to_sym) # Uniform interface

        # For backwards compatibility, kid_generator may be specified in the parameters
        options[:kid_generator] ||= @parameters.delete(:kid_generator)

        # Make sure the key has a kid
        kid_generator = options[:kid_generator] || ::JWT.configuration.jwk.kid_generator
        self[:kid] ||= kid_generator.new(self).generate
      end

      def kid
        self[:kid]
      end

      def hash
        self[:kid].hash
      end

      def [](key)
        @parameters[key.to_sym]
      end

      def []=(key, value)
        @parameters[key.to_sym] = value
      end

      def ==(other)
        self[:kid] == other[:kid]
      end

      alias eql? ==

      def <=>(other)
        self[:kid] <=> other[:kid]
      end

      private

      attr_reader :parameters
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
jwt-2.7.1 lib/jwt/jwk/key_base.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/jwt-2.7.0/lib/jwt/jwk/key_base.rb
jwt-2.7.0 lib/jwt/jwk/key_base.rb
jwt-2.6.0 lib/jwt/jwk/key_base.rb