Class: Relish::EncryptionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/relish/encryption_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(static_secrets, secrets) ⇒ EncryptionHelper

Returns a new instance of EncryptionHelper.



10
11
12
13
# File 'lib/relish/encryption_helper.rb', line 10

def initialize(static_secrets, secrets)
  @static_secrets = static_secrets.is_a?(String) ? [static_secrets] : static_secrets
  @secrets = secrets
end

Instance Method Details

#decrypt(token) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/relish/encryption_helper.rb', line 19

def decrypt(token)
  plain = nil
  hmac_secrets.each do |secret|
    plain = decrypt_with_secret(secret, token)
    break if plain
  end
  raise RelishDecryptionFailed unless plain
  plain
end

#encrypt(value) ⇒ Object



15
16
17
# File 'lib/relish/encryption_helper.rb', line 15

def encrypt(value)
  Fernet.generate(hmac_secrets.first[0, 32], value)
end

#inspectObject Also known as: to_s



29
30
31
# File 'lib/relish/encryption_helper.rb', line 29

def inspect
  "#<Relish::EncryptionHelper>"
end