class Sandal::Enc::Alg::Direct

The direct (“dir”) key encryption algorithm, which uses a pre-shared symmetric key.

Constants

NAME

The JWA name of the algorithm.

Attributes

preshared_key[R]

@return [String] The pre-shared symmetric key.

Public Class Methods

new(preshared_key) click to toggle source

Initialises a new instance.

@param preshared_key [String] The pre-shared symmetric key.

# File lib/sandal/enc/alg/direct.rb, line 19
def initialize(preshared_key)
  @preshared_key = preshared_key
end

Public Instance Methods

decrypt_key(encrypted_key) click to toggle source

Returns the pre-shared content key.

@param encrypted_key [String] The encrypted key. @return [String] The pre-shared symmetric key. @raise [Sandal::InvalidTokenError] encrypted_key is not nil or empty.

# File lib/sandal/enc/alg/direct.rb, line 41
def decrypt_key(encrypted_key)
  unless encrypted_key.nil? || encrypted_key.empty?
    raise Sandal::InvalidTokenError, "Tokens using direct key exchange must not include a content key."
  end
  @preshared_key
end
encrypt_key(key) click to toggle source

Returns an empty string as the key is not included in JWE tokens using direct key exchange.

@param key [String] This parameter is ignored. @return [String] An empty string.

# File lib/sandal/enc/alg/direct.rb, line 32
def encrypt_key(key)
  ""
end
name() click to toggle source

The JWA name of the algorithm.

# File lib/sandal/enc/alg/direct.rb, line 24
def name
  NAME
end