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.

Parameters:

  • cmk (String)

    The pre-shared content master key.



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

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

Instance Attribute Details

#cmkString (readonly)

Returns The pre-shared content master key key.

Returns:

  • (String)

    The pre-shared content master key key.



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

def cmk
  @cmk
end

#nameString (readonly)

Returns The JWA name of the algorithm.

Returns:

  • (String)

    The JWA name of the algorithm.



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

def name
  @name
end

Instance Method Details

#decrypt_cmk(encrypted_cmk) ⇒ String

Returns the pre-shared content master key.

Parameters:

  • encrypted_cmk (String)

    The encrypted content master key.

Returns:

  • (String)

    The pre-shared content master key.

Raises:



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

def decrypt_cmk(encrypted_cmk)
  unless encrypted_cmk.nil? || encrypted_cmk.empty?
    raise Sandal::TokenError, 'The token should not include an encrypted content master key.' 
  end
  @cmk
end

#encrypt_cmk(cmk) ⇒ String

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

Parameters:

  • cmk (String)

    This parameter is ignored.

Returns:

  • (String)

    An empty string.



28
29
30
# File 'lib/sandal/enc/alg/direct.rb', line 28

def encrypt_cmk(cmk)
  ''
end