rubocop update and resolutions
This commit is contained in:
@ -26,18 +26,28 @@ class CryptSerializer
|
||||
raise "Attribute was supposed to be a `String`, but was instead a `#{value.class}`"
|
||||
end
|
||||
|
||||
cipher.encrypt
|
||||
parts = [cipher.random_key, cipher.random_iv, cipher.update(value) + cipher.final]
|
||||
Base64.urlsafe_encode64 Marshal.dump(parts)
|
||||
build_cipher value
|
||||
end
|
||||
|
||||
def decrypt(value)
|
||||
return value if value.nil?
|
||||
|
||||
parts = Marshal.load Base64.urlsafe_decode64(value)
|
||||
cipher.decrypt
|
||||
cipher.key = parts[0]
|
||||
cipher.iv = parts[1]
|
||||
cipher.update(parts[2]) + cipher.final
|
||||
decode_cipher parts
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_cipher value
|
||||
cipher.encrypt
|
||||
parts = [cipher.random_key, cipher.random_iv, cipher.update(value) + cipher.final]
|
||||
Base64.urlsafe_encode64 Marshal.dump(parts)
|
||||
end
|
||||
|
||||
def decode_cipher parts
|
||||
cipher.decrypt
|
||||
cipher.key = parts[0]
|
||||
cipher.iv = parts[1]
|
||||
cipher.update(parts[2]) + cipher.final
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user