rubocop update and resolutions

This commit is contained in:
2016-09-11 09:57:55 -05:00
parent 9362f506ee
commit b063f188b9
5 changed files with 23 additions and 9 deletions

View File

@ -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