Class: JWT::JWK::KeyBase

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt/jwk/key_base.rb

Overview

Base for JWK implementations

Direct Known Subclasses

EC, HMAC, OKPRbNaCl, RSA

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, params = {}) ⇒ KeyBase

Returns a new instance of KeyBase.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jwt/jwk/key_base.rb', line 12

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

Class Method Details

.inherited(klass) ⇒ Object



7
8
9
10
# File 'lib/jwt/jwk/key_base.rb', line 7

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

Instance Method Details

#<=>(other) ⇒ Object



47
48
49
50
51
# File 'lib/jwt/jwk/key_base.rb', line 47

def <=>(other)
  return nil unless other.is_a?(::JWT::JWK::KeyBase)

  self[:kid] <=> other[:kid]
end

#==(other) ⇒ Object Also known as: eql?



41
42
43
# File 'lib/jwt/jwk/key_base.rb', line 41

def ==(other)
  other.is_a?(::JWT::JWK::KeyBase) && self[:kid] == other[:kid]
end

#[](key) ⇒ Object



33
34
35
# File 'lib/jwt/jwk/key_base.rb', line 33

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

#[]=(key, value) ⇒ Object



37
38
39
# File 'lib/jwt/jwk/key_base.rb', line 37

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

#hashObject



29
30
31
# File 'lib/jwt/jwk/key_base.rb', line 29

def hash
  self[:kid].hash
end

#kidObject



25
26
27
# File 'lib/jwt/jwk/key_base.rb', line 25

def kid
  self[:kid]
end