Module: JOSE::JWK::KTY

Defined in:
lib/jose/jwk/kty.rb

Class Method Summary collapse

Class Method Details

.from_key(object) ⇒ Object



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

def self.from_key(object)
  object = object.__getobj__ if object.is_a?(JOSE::JWK::PKeyProxy)
  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: #{object.class.name}"
  end
end

.key_encryptor(kty, fields, key) ⇒ Object



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

def self.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