Class: Nygma::Encryptor
- Inherits:
-
Object
- Object
- Nygma::Encryptor
- Defined in:
- lib/nygma/encryptor.rb
Constant Summary collapse
- UnknownEncryptionError =
Class.new(StandardError)
- UnknownDecryptionError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#crypt ⇒ Object
Returns the value of attribute crypt.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#crypt ⇒ Object
Returns the value of attribute crypt.
4 5 6 |
# File 'lib/nygma/encryptor.rb', line 4 def crypt @crypt end |
Class Method Details
.crypt!(key, salt) ⇒ Object
10 11 12 |
# File 'lib/nygma/encryptor.rb', line 10 def crypt!(key, salt) new(key, salt).call end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 |
# File 'lib/nygma/encryptor.rb', line 15 def call _key = ActiveSupport::KeyGenerator.new(key). generate_key(salt) self.crypt = ActiveSupport::MessageEncryptor.new(_key) self end |
#decrypt(payload) ⇒ Object
28 29 30 31 32 |
# File 'lib/nygma/encryptor.rb', line 28 def decrypt(payload) crypt.decrypt_and_verify(payload) rescue => ex raise UnknownDecryptionError.new(ex) end |
#encrypt(payload) ⇒ Object
22 23 24 25 26 |
# File 'lib/nygma/encryptor.rb', line 22 def encrypt(payload) crypt.encrypt_and_sign(payload) rescue => ex raise UnknownEncryptionError.new(ex) end |