diff options
| author | Randy Morgan <[email protected]> | 2012-05-20 14:28:22 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-05-20 14:28:22 +0900 |
| commit | a2ffc47d7589eb6e9d0cecf880ec1c84ddfd8316 (patch) | |
| tree | d114f238ba6d9e015709b97c330237ed11eb5a67 /lib | |
| parent | 0aede23fd2d8649bce223b36c28e5c77bf3749c4 (diff) | |
| download | caxlsx-a2ffc47d7589eb6e9d0cecf880ec1c84ddfd8316.tar.gz caxlsx-a2ffc47d7589eb6e9d0cecf880ec1c84ddfd8316.zip | |
more work on sheet protection. Protection is working, but specifying a password does not work. Having a bit of trouble implementing the hashing algorithm...
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/sheet_protection.rb | 19 |
1 files changed, 9 insertions, 10 deletions
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 << '<sheetProtection ' - str << instance_values.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ') + str << instance_values.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v.to_s}"} }.join(' ') str << '/>' end end |
