Class: JOSE::JWE::ALG_dir

Inherits:
Object
  • Object
show all
Defined in:
lib/jose/jwe/alg_dir.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_map(fields) ⇒ Object

JOSE::JWE callbacks


5
6
7
8
9
10
11
12
# File 'lib/jose/jwe/alg_dir.rb', line 5

def self.from_map(fields)
  case fields['alg']
  when 'dir'
    return new(), fields.delete('alg')
  else
    raise ArgumentError, "invalid 'alg' for JWE: #{fields['alg'].inspect}"
  end
end

Instance Method Details

#generate_key(fields, enc) ⇒ Object

JOSE::JWE::ALG callbacks


20
21
22
# File 'lib/jose/jwe/alg_dir.rb', line 20

def generate_key(fields, enc)
  return JOSE::JWE::ALG.generate_key([:oct, enc.bits.div(8)], 'dir', enc.algorithm)
end

#key_decrypt(key, enc, encrypted_key) ⇒ Object


24
25
26
27
28
29
30
# File 'lib/jose/jwe/alg_dir.rb', line 24

def key_decrypt(key, enc, encrypted_key)
  if key.is_a?(String)
    return key
  else
    return key.kty.derive_key
  end
end

#key_encrypt(key, enc, decrypted_key) ⇒ Object


32
33
34
# File 'lib/jose/jwe/alg_dir.rb', line 32

def key_encrypt(key, enc, decrypted_key)
  return '', self
end

#next_cek(key, enc) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/jose/jwe/alg_dir.rb', line 36

def next_cek(key, enc)
  if key.is_a?(String)
    return key
  else
    return key.kty.derive_key
  end
end

#to_map(fields) ⇒ Object


14
15
16
# File 'lib/jose/jwe/alg_dir.rb', line 14

def to_map(fields)
  return fields.put('alg', 'dir')
end