Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change to return a 404 if decryption fails
  • Loading branch information
michaelavila committed Nov 15, 2015
1 parent 76f552f commit b62fbe8
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions app/controllers/messages_controller.rb
Expand Up @@ -19,28 +19,24 @@ def create
end

def show
begin
@decrypted_text = @message.decrypt_text(params[:key])
if @message.file_contents.nil?
@message.destroy
end
rescue OpenSSL::Cipher::CipherError
raise "Could Not Decrypt"
@decrypted_text = @message.decrypt_text(params[:key])
if @message.file_contents.nil?
@message.destroy
end
rescue OpenSSL::Cipher::CipherError
raise ActiveRecord::RecordNotFound
end

def download
begin
decrypted_file_contents = @message.decrypt_file_contents(params[:key])
@message.destroy
send_data(
decrypted_file_contents,
type: @message.file_mime_type,
filename: @message.file_name,
)
rescue OpenSSL::Cipher::CipherError
raise "Could Not Decrypt"
end
decrypted_file_contents = @message.decrypt_file_contents(params[:key])
@message.destroy
send_data(
decrypted_file_contents,
type: @message.file_mime_type,
filename: @message.file_name,
)
rescue OpenSSL::Cipher::CipherError
raise ActiveRecord::RecordNotFound
end

def set_message
Expand Down

0 comments on commit b62fbe8

Please sign in to comment.