summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-07-05 11:09:35 +0200
committerGeremia Taglialatela <[email protected]>2023-07-05 11:09:35 +0200
commitd52600dfb373323641c95c3c9be952c32fee8a1a (patch)
treee18b100cb29abb6dba3fcb0dbfa231fb6396fc65 /lib
parent692be9e99e0a76d5f6d0b0527466998ca558fe96 (diff)
downloadcaxlsx-d52600dfb373323641c95c3c9be952c32fee8a1a.tar.gz
caxlsx-d52600dfb373323641c95c3c9be952c32fee8a1a.zip
Fix offenses in sheet protection
- Lint/AmbiguousOperatorPrecedence - Style/PerlBackrefs - Style/StringChars - Style/UnpackFirst
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/sheet_protection.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/axlsx/workbook/worksheet/sheet_protection.rb b/lib/axlsx/workbook/worksheet/sheet_protection.rb
index ce39b1b4..abf5e452 100644
--- a/lib/axlsx/workbook/worksheet/sheet_protection.rb
+++ b/lib/axlsx/workbook/worksheet/sheet_protection.rb
@@ -87,25 +87,25 @@ module Axlsx
encoded_password = encode_password(password)
password_as_hex = [encoded_password].pack("v")
- password_as_string = password_as_hex.unpack("H*").first.upcase
+ password_as_string = password_as_hex.unpack1("H*").upcase
password_as_string[2..3] + password_as_string[0..1]
end
# Encodes a given password
# Based on the algorithm provided by Daniel Rentz of OpenOffice.
- # http://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
+ # https://www.openoffice.org/sc/excelfileformat.pdf, Revision 1.42, page 115 (21.05.2012)
# @return [String]
def encode_password(password)
i = 0
- chars = password.split("")
+ chars = password.chars
count = chars.size
chars.collect! do |char|
i += 1
- char = char.unpack('c')[0] << i # ord << i
+ char = char.unpack1('c') << i # ord << i
low_15 = char & 0x7fff
- high_15 = char & 0x7fff << 15
+ high_15 = char & (0x7fff << 15)
high_15 = high_15 >> 15
low_15 | high_15
end