Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Adding the option to retrieve a cypher from the model #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/carrierwave/securefile/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down