Class: JWT::JWK::AKP

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

Defined Under Namespace

Classes: NullKidGenerator

Constant Summary collapse

KTY =
"AKP".freeze
KTYS =
[
  KTY,
  PQCrypto::Signature::PublicKey,
  JWT::JWK::AKP,
].freeze
AKP_KEY_ELEMENTS =
%i[kty alg pub priv].freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AKP.



22
23
24
25
26
27
28
29
30
31
# File 'lib/pq_crypto/jwt/jwk/akp.rb', line 22

def initialize(key, params = nil, options = {})
  params ||= {}
  options ||= {}
  options = { kid_generator: NullKidGenerator }.merge(options)
  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

Instance Method Details

#[]=(key, value) ⇒ Object

Raises:

  • (ArgumentError)


65
66
67
68
69
# File 'lib/pq_crypto/jwt/jwk/akp.rb', line 65

def []=(key, value)
  raise ArgumentError, "cannot overwrite cryptographic key attributes" if AKP_KEY_ELEMENTS.include?(key.to_sym)

  super
end

#export(_options = {}) ⇒ Object



49
50
51
# File 'lib/pq_crypto/jwt/jwk/akp.rb', line 49

def export(_options = {})
  parameters.clone.tap { |exported| exported.delete(:priv) }
end

#jwaObject



61
62
63
# File 'lib/pq_crypto/jwt/jwk/akp.rb', line 61

def jwa
  PQCrypto::JWT.algorithm_for(self[:alg]) || super
end

#key_digestObject



57
58
59
# File 'lib/pq_crypto/jwt/jwk/akp.rb', line 57

def key_digest
  PQCrypto::JWT::JWK.thumbprint(string_export)
end

#membersObject



53
54
55
# File 'lib/pq_crypto/jwt/jwk/akp.rb', line 53

def members
  %i[alg kty pub].each_with_object({}) { |key, out| out[key] = self[key] }
end

#private?Boolean

Returns:

  • (Boolean)


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

def private?
  false
end

#public_keyObject



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

def public_key
  @public_key ||= PQCrypto::JWT::JWK.public_key_from_jwk(string_export)
end

#signing_keyObject



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

def signing_key
  public_key
end

#verify_keyObject



45
46
47
# File 'lib/pq_crypto/jwt/jwk/akp.rb', line 45

def verify_key
  public_key
end