Class: JWT::JWK::KeyBase
- Inherits:
-
Object
- Object
- JWT::JWK::KeyBase
- Defined in:
- lib/jwt/jwk/key_base.rb
Overview
Base for JWK implementations
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #hash ⇒ Object
-
#initialize(options, params = {}) ⇒ KeyBase
constructor
A new instance of KeyBase.
- #jwa ⇒ Object
- #kid ⇒ Object
- #sign(**kwargs) ⇒ Object
- #verify(**kwargs) ⇒ Object
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(, params = {}) ||= {} @parameters = params.transform_keys(&:to_sym) # Uniform interface # For backwards compatibility, kid_generator may be specified in the parameters [:kid_generator] ||= @parameters.delete(:kid_generator) # Make sure the key has a kid kid_generator = [:kid_generator] || ::JWT.configuration.jwk.kid_generator self[:kid] ||= kid_generator.new(self).generate end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
69 70 71 |
# File 'lib/jwt/jwk/key_base.rb', line 69 def parameters @parameters end |
Instance Method Details
#<=>(other) ⇒ Object
55 56 57 58 59 |
# File 'lib/jwt/jwk/key_base.rb', line 55 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 |
#hash ⇒ Object
29 30 31 |
# File 'lib/jwt/jwk/key_base.rb', line 29 def hash self[:kid].hash end |
#jwa ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/jwt/jwk/key_base.rb', line 61 def jwa raise JWT::JWKError, 'Could not resolve the JWA, the "alg" parameter is missing' unless self[:alg] JWA.resolve(self[:alg]).tap do |jwa| raise JWT::JWKError, 'none algorithm usage not supported via JWK' if jwa.is_a?(JWA::None) end end |
#kid ⇒ Object
25 26 27 |
# File 'lib/jwt/jwk/key_base.rb', line 25 def kid self[:kid] end |
#sign(**kwargs) ⇒ Object
49 50 51 |
# File 'lib/jwt/jwk/key_base.rb', line 49 def sign(**kwargs) jwa.sign(**kwargs, signing_key: signing_key) end |
#verify(**kwargs) ⇒ Object
45 46 47 |
# File 'lib/jwt/jwk/key_base.rb', line 45 def verify(**kwargs) jwa.verify(**kwargs, verification_key: verify_key) end |