Class: Relish::EncryptionHelper
- Inherits:
-
Object
- Object
- Relish::EncryptionHelper
- Defined in:
- lib/relish/encryption_helper.rb
Instance Method Summary collapse
- #decrypt(key, token) ⇒ Object
- #encrypt(key, value) ⇒ Object
-
#initialize(static_secret, secrets) ⇒ EncryptionHelper
constructor
A new instance of EncryptionHelper.
- #inspect ⇒ Object (also: #to_s)
- #upgrade(key, token) ⇒ Object
Constructor Details
#initialize(static_secret, secrets) ⇒ EncryptionHelper
Returns a new instance of EncryptionHelper.
10 11 12 13 |
# File 'lib/relish/encryption_helper.rb', line 10 def initialize(static_secret, secrets) @static_secret = static_secret @secrets = secrets end |
Instance Method Details
#decrypt(key, token) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/relish/encryption_helper.rb', line 21 def decrypt(key, token) hmac_secrets.each do |secret| if verifier = verifier(secret, token) return verifier.data[key] if verifier.valid? end end raise RelishDecryptionFailed end |
#encrypt(key, value) ⇒ Object
15 16 17 18 19 |
# File 'lib/relish/encryption_helper.rb', line 15 def encrypt(key, value) Fernet::Legacy.generate(hmac_secrets.first) do |gen| gen.data = {key => value} end end |
#inspect ⇒ Object Also known as: to_s
37 38 39 |
# File 'lib/relish/encryption_helper.rb', line 37 def inspect "#<Relish::EncryptionHelper>" end |
#upgrade(key, token) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/relish/encryption_helper.rb', line 30 def upgrade(key, token) if verifier = verifier(hmac_secrets.first, token) return encrypt(key, verifier.data[key]) if verifier.valid? end raise RelishDecryptionFailed end |