Module: JOSE::JWK::KTY

Extended by:
KTY
Included in:
KTY
Defined in:
lib/jose/jwk/kty.rb

Instance Method Summary collapse

Instance Method Details

#from_key(object) ⇒ Object


5
6
7
8
9
10
11
12
13
14
# File 'lib/jose/jwk/kty.rb', line 5

def from_key(object)
  case object
  when OpenSSL::PKey::EC
    return JOSE::JWK::KTY_EC.from_key(object)
  when OpenSSL::PKey::RSA
    return JOSE::JWK::KTY_RSA.from_key(object)
  else
    raise ArgumentError, "'object' is not a recognized key type"
  end
end

#key_encryptor(kty, fields, key) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jose/jwk/kty.rb', line 16

def key_encryptor(kty, fields, key)
  if key.is_a?(String)
    return JOSE::Map[
      'alg' => 'PBES2-HS256+A128KW',
      'cty' => 'jwk+json',
      'enc' => 'A128GCM',
      'p2c' => 4096,
      'p2s' => JOSE.urlsafe_encode64(SecureRandom.random_bytes(16))
    ]
  else
    raise ArgumentError, "unhandled key type for key_encryptor"
  end
end