Class: ActiveRecordEncryption::Testing::TestCipher

Inherits:
Encryptor::Cipher show all
Defined in:
lib/active_record_encryption/testing/test_cipher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (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