Changes the digest used for attachments to SHA256 (#25240).

Patch by Jens Kraemer.

git-svn-id: http://svn.redmine.org/redmine/trunk@16454 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2017-04-03 11:11:36 +00:00
parent 9441ab0ca8
commit 30f7be9c19
4 changed files with 20 additions and 12 deletions

View File

@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require "digest/md5"
require "digest"
require "fileutils"
class Attachment < ActiveRecord::Base
@@ -116,20 +116,20 @@ class Attachment < ActiveRecord::Base
unless File.directory?(path)
FileUtils.mkdir_p(path)
end
md5 = Digest::MD5.new
sha = Digest::SHA256.new
File.open(diskfile, "wb") do |f|
if @temp_file.respond_to?(:read)
buffer = ""
while (buffer = @temp_file.read(8192))
f.write(buffer)
md5.update(buffer)
sha.update(buffer)
end
else
f.write(@temp_file)
md5.update(@temp_file)
sha.update(@temp_file)
end
end
self.digest = md5.hexdigest
self.digest = sha.hexdigest
end
@temp_file = nil