Class: JOSE::JWE::ALG_AES_KW

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bitsObject

Returns the value of attribute bits

Returns:

  • (Object)

    the current value of bits



1
2
3
# File 'lib/jose/jwe/alg_aes_kw.rb', line 1

def bits
  @bits
end

Class Method Details

.from_map(fields) ⇒ Object

JOSE::JWE callbacks



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jose/jwe/alg_aes_kw.rb', line 5

def self.from_map(fields)
  bits = case fields['alg']
  when 'A128KW'
    128
  when 'A192KW'
    192
  when 'A256KW'
    256
  else
    raise ArgumentError, "invalid 'alg' for JWE: #{fields['alg'].inspect}"
  end
  return new(bits), fields.except('alg')
end

Instance Method Details

#algorithmObject

API functions



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jose/jwe/alg_aes_kw.rb', line 53

def algorithm
  case bits
  when 128
    'A128KW'
  when 192
    'A192KW'
  when 256
    'A256KW'
  else
    raise ArgumentError, "unhandled JOSE::JWE::ALG_AES_KW bits: #{bits.inspect}"
  end
end

#generate_key(fields, enc) ⇒ Object

JOSE::JWE::ALG callbacks



25
26
27
# File 'lib/jose/jwe/alg_aes_kw.rb', line 25

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

#key_decrypt(key, enc, encrypted_key) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/jose/jwe/alg_aes_kw.rb', line 29

def key_decrypt(key, enc, encrypted_key)
  if key.is_a?(JOSE::JWK)
    key = key.kty.derive_key
  end
  derived_key = key
  decrypted_key = JOSE::JWA::AES_KW.unwrap(encrypted_key, derived_key)
  return decrypted_key
end

#key_encrypt(key, enc, decrypted_key) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/jose/jwe/alg_aes_kw.rb', line 38

def key_encrypt(key, enc, decrypted_key)
  if key.is_a?(JOSE::JWK)
    key = key.kty.derive_key
  end
  derived_key = key
  encrypted_key = JOSE::JWA::AES_KW.wrap(decrypted_key, derived_key)
  return encrypted_key, self
end

#next_cek(key, enc) ⇒ Object



47
48
49
# File 'lib/jose/jwe/alg_aes_kw.rb', line 47

def next_cek(key, enc)
  return enc.next_cek, self
end

#to_map(fields) ⇒ Object



19
20
21
# File 'lib/jose/jwe/alg_aes_kw.rb', line 19

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