From ff8842066289edf71ce1f0d1fca165878222e708 Mon Sep 17 00:00:00 2001 From: Shlomi Zadok Date: Wed, 30 Jan 2013 14:18:16 +0200 Subject: [PATCH] Try to retrieve a cypher from model. --- lib/carrierwave/securefile/uploader.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/carrierwave/securefile/uploader.rb b/lib/carrierwave/securefile/uploader.rb index bf61aee..6a92f51 100644 --- a/lib/carrierwave/securefile/uploader.rb +++ b/lib/carrierwave/securefile/uploader.rb @@ -18,7 +18,15 @@ def self.secure_file(model=nil, file) encryptor = CarrierWave::SecureFile::AESFileEncrypt.new(aes_key, configuration.aes_iv) encryptor.do ext_file, file else - encryptor = CarrierWave::SecureFile.cryptable.new(CarrierWave::SecureFile.cypher) + + # Try to retrieve a cypher from model. + if model.respond_to? :cypher + cypher = model.cypher + else + cypher = CarrierWave::SecureFile.cypher + end + + encryptor = CarrierWave::SecureFile.cryptable.new(cypher) encryptor.encrypt_file(ext_file, file) end File.unlink(ext_file)