Class: Sandal::Enc::Alg::Direct
- Inherits:
-
Object
- Object
- Sandal::Enc::Alg::Direct
- Defined in:
- lib/sandal/enc/alg/direct.rb
Overview
The direct (“dir”) key encryption algorithm, which uses a pre-shared symmetric key.
Constant Summary collapse
- NAME =
The JWA name of the algorithm.
"dir"
Instance Attribute Summary collapse
-
#preshared_key ⇒ String
readonly
The pre-shared symmetric key.
Instance Method Summary collapse
-
#decrypt_key(encrypted_key) ⇒ String
Returns the pre-shared content key.
-
#encrypt_key(key) ⇒ String
Returns an empty string as the key is not included in JWE tokens using direct key exchange.
-
#initialize(preshared_key) ⇒ Direct
constructor
Initialises a new instance.
-
#name ⇒ Object
The JWA name of the algorithm.
Constructor Details
#initialize(preshared_key) ⇒ Direct
Initialises a new instance.
19 20 21 |
# File 'lib/sandal/enc/alg/direct.rb', line 19 def initialize(preshared_key) @preshared_key = preshared_key end |
Instance Attribute Details
#preshared_key ⇒ String (readonly)
Returns The pre-shared symmetric key.
14 15 16 |
# File 'lib/sandal/enc/alg/direct.rb', line 14 def preshared_key @preshared_key end |
Instance Method Details
#decrypt_key(encrypted_key) ⇒ String
Returns the pre-shared content key.
41 42 43 44 45 46 |
# 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) ⇒ String
Returns an empty string as the key is not included in JWE tokens using direct key exchange.
32 33 34 |
# File 'lib/sandal/enc/alg/direct.rb', line 32 def encrypt_key(key) "" end |
#name ⇒ Object
The JWA name of the algorithm.
24 25 26 |
# File 'lib/sandal/enc/alg/direct.rb', line 24 def name NAME end |