Class: Sandal::Enc::Alg::Direct

Inherits:
Object
  • Object
show all
Defined in:
lib/sandal/enc/alg/direct.rb

Overview

The direct (“dir”) key encryption mechanism, which uses a pre-shared content master key.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmk) ⇒ Direct

Creates a new instance.



20
21
22
23
# File 'lib/sandal/enc/alg/direct.rb', line 20

def initialize(cmk)
  @name = 'dir'
  @cmk = cmk
end

Instance Attribute Details

#cmkString (readonly)



15
16
17
# File 'lib/sandal/enc/alg/direct.rb', line 15

def cmk
  @cmk
end

#nameString (readonly)



12
13
14
# File 'lib/sandal/enc/alg/direct.rb', line 12

def name
  @name
end

Instance Method Details

#decrypt_cmk(encrypted_cmk) ⇒ String

Returns the pre-shared content master key.

Raises:



39
40
41
42
43
44
# File 'lib/sandal/enc/alg/direct.rb', line 39

def decrypt_cmk(encrypted_cmk)
  unless encrypted_cmk.nil? || encrypted_cmk.empty?
    raise Sandal::TokenError, 'Token must not include encrypted CMK.' 
  end
  @cmk
end

#encrypt_cmk(cmk) ⇒ String

Returns an empty string as the content master key is not included in the JWE token.



30
31
32
# File 'lib/sandal/enc/alg/direct.rb', line 30

def encrypt_cmk(cmk)
  ''
end