From a2ffc47d7589eb6e9d0cecf880ec1c84ddfd8316 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Sun, 20 May 2012 14:28:22 +0900 Subject: more work on sheet protection. Protection is working, but specifying a password does not work. Having a bit of trouble implementing the hashing algorithm... --- lib/axlsx/workbook/worksheet/sheet_protection.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb index 66687f75..836f6513 100644 --- a/lib/axlsx/workbook/worksheet/sheet_protection.rb +++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb @@ -107,7 +107,7 @@ module Axlsx # If 1 or true then the sheet is protected. # If 0 or false then the sheet is not protected. # @return [Boolean] - # default false + # default true attr_reader :sheet # If 1 or true then sorting should not be allowed when the sheet is protected. @@ -141,8 +141,8 @@ module Axlsx # @option options [String] password. The password required for unlocking. @see SheetProtection#password= # @option options [Boolean] objects @see SheetProtection#objects def initialize(options={}) - @sheet = @objects = @scenarios = @select_locked_cells = @select_unlocked_cells = false - @format_cells = @format_rows = @format_columns = @insert_columns = @insert_rows = @insert_hyperlinks = @delete_columns = @delete_rows = @sort = @auto_filter = @pivot_tables = true + @objects = @scenarios = @select_locked_cells = @select_unlocked_cells = false + @sheet = @format_cells = @format_rows = @format_columns = @insert_columns = @insert_rows = @insert_hyperlinks = @delete_columns = @delete_rows = @sort = @auto_filter = @pivot_tables = true options.each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end @@ -163,19 +163,18 @@ module Axlsx @salt_value = @spin_count = @hash_value = v if v == nil return if v == nil require 'digest/sha1' - @spin_count = 10000 - @salt_value = Digest::SHA1.hexdigest(rand(36**8).to_s(36)) - - salty = @salt_value + v.to_s - @hash_value = Digest::SHA1.hexdigest(salty) + @spin_count = 0 + @salt_value = Digest::SHA1.new << rand(36**8).to_s(36) + @hash_value = @salt_value.to_s + v + @hash_value = Digest::SHA1.new << @hash_value @spin_count.times do |count| - @hash_value = Digest::SHA1.hexdigest(@hash_value) + count.to_s + @hash_value = @hash_value.update(count.to_s.bytes.to_a.pack('L')) end end def to_xml_string(str = '') str << '' end end -- cgit v1.2.3