Class: JWT::EdDSA::JWK::OKP

Inherits:
JWK::KeyBase
  • Object
show all
Defined in:
lib/jwt/eddsa/jwk/okp.rb

Overview

Constant Summary collapse

KTY =
"OKP"
KTYS =
[KTY, JWT::EdDSA::JWK::OKP, Ed25519::SigningKey, Ed25519::VerifyKey].freeze
OKP_PUBLIC_KEY_ELEMENTS =
%i[kty n x].freeze
OKP_PRIVATE_KEY_ELEMENTS =
%i[d].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, params = nil, options = {}) ⇒ OKP

Returns a new instance of OKP.



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

def initialize(key, params = nil, options = {})
  params ||= {}
  # For backwards compatibility when kid was a String
  params = { kid: params } if params.is_a?(String)

  key_params = extract_key_params(key)

  params = params.transform_keys(&:to_sym)
  check_jwk_params!(key_params, params)
  super(options, key_params.merge(params))
end

Class Method Details

.import(jwk_data) ⇒ Object



113
114
115
# File 'lib/jwt/eddsa/jwk/okp.rb', line 113

def import(jwk_data)
  new(jwk_data)
end

Instance Method Details

#export(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/jwt/eddsa/jwk/okp.rb', line 49

def export(options = {})
  exported = parameters.clone
  unless private? && options[:include_private] == true
    exported.reject! do |k, _|
      OKP_PRIVATE_KEY_ELEMENTS.include?(k)
    end
  end
  exported
end

#key_digestObject



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

def key_digest
  ::JWT::JWK::Thumbprint.new(self).to_s
end

#membersObject



45
46
47
# File 'lib/jwt/eddsa/jwk/okp.rb', line 45

def members
  OKP_PUBLIC_KEY_ELEMENTS.each_with_object({}) { |i, h| h[i] = self[i] }
end

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  !signing_key.nil?
end

#signing_keyObject



31
32
33
34
35
# File 'lib/jwt/eddsa/jwk/okp.rb', line 31

def signing_key
  return @signing_key if defined?(@signing_key)

  @signing_key = signing_key_from_parameters
end

#verify_keyObject



25
26
27
28
29
# File 'lib/jwt/eddsa/jwk/okp.rb', line 25

def verify_key
  return @verify_key if defined?(@verify_key)

  @verify_key = verify_key_from_parameters
end