Class: ActiveRecordEncryption::Testing::TestCipher
- Inherits:
-
Encryptor::Cipher
- Object
- Encryptor::Cipher
- ActiveRecordEncryption::Testing::TestCipher
- Defined in:
- lib/active_record_encryption/testing/test_cipher.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #decrypt(value) ⇒ Object
- #encrypt(value) ⇒ Object
-
#initialize(key: SecureRandom.hex) ⇒ TestCipher
constructor
A new instance of TestCipher.
Constructor Details
#initialize(key: SecureRandom.hex) ⇒ TestCipher
Returns a new instance of TestCipher.
10 11 12 |
# File 'lib/active_record_encryption/testing/test_cipher.rb', line 10 def initialize(key: SecureRandom.hex) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/active_record_encryption/testing/test_cipher.rb', line 8 def key @key end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/active_record_encryption/testing/test_cipher.rb', line 14 def ==(other) other.is_a?(self.class) && key == other.key end |
#decrypt(value) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/active_record_encryption/testing/test_cipher.rb', line 22 def decrypt(value) value = value.to_s if value.match(/#{key}$/) super(value.sub(/#{key}$/, '')) else raise InvalidMessage, 'invalid value given' end end |
#encrypt(value) ⇒ Object
18 19 20 |
# File 'lib/active_record_encryption/testing/test_cipher.rb', line 18 def encrypt(value) super("#{value}#{key}") end |