Class: JWT::JWK::OKPRbNaCl

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

Overview

JSON Web Key (JWK) representation for Ed25519 keys

Constant Summary collapse

KTY =
'OKP'
KTYS =
[KTY, JWT::JWK::OKPRbNaCl, RbNaCl::Signatures::Ed25519::SigningKey, RbNaCl::Signatures::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

Methods inherited from KeyBase

#<=>, #==, #[], #[]=, #hash, inherited, #kid

Constructor Details

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

Returns a new instance of OKPRbNaCl.



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

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



103
104
105
# File 'lib/jwt/jwk/okp_rbnacl.rb', line 103

def import(jwk_data)
  new(jwk_data)
end

Instance Method Details

#export(options = {}) ⇒ Object



49
50
51
52
53
# File 'lib/jwt/jwk/okp_rbnacl.rb', line 49

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

#key_digestObject



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

def key_digest
  Thumbprint.new(self).to_s
end

#membersObject



45
46
47
# File 'lib/jwt/jwk/okp_rbnacl.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/jwk/okp_rbnacl.rb', line 41

def private?
  !signing_key.nil?
end

#signing_keyObject



31
32
33
34
35
# File 'lib/jwt/jwk/okp_rbnacl.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/jwk/okp_rbnacl.rb', line 25

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

  @verify_key = verify_key_from_parameters
end