Skip to content

Commit 3d7c9c5

Browse files
committed
(PUP-11993) Style/UnpackFirst
This commit enables the Style/UnpackFirst cop and fixes 5 autocorrectable offenses.
1 parent 144d956 commit 3d7c9c5

File tree

4 files changed

+4
-11
lines changed

4 files changed

+4
-11
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,6 @@ Style/TrailingUnderscoreVariable:
762762
Style/TrivialAccessors:
763763
Enabled: false
764764

765-
# This cop supports safe auto-correction (--auto-correct).
766-
Style/UnpackFirst:
767-
Exclude:
768-
- 'lib/puppet/file_serving/http_metadata.rb'
769-
- 'lib/puppet/provider/nameservice/directoryservice.rb'
770-
- 'lib/puppet/provider/user/directoryservice.rb'
771-
772765
# This cop supports safe auto-correction (--auto-correct).
773766
Style/VariableInterpolation:
774767
Exclude:

lib/puppet/file_serving/http_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(http_response, path = '/dev/null')
2020
checksum = http_response['content-md5']
2121
if checksum
2222
# convert base64 digest to hex
23-
checksum = checksum.unpack("m").first.unpack("H*").first
23+
checksum = checksum.unpack1("m").unpack1("H*")
2424
@checksums[:md5] = "{md5}#{checksum}"
2525
end
2626

lib/puppet/provider/nameservice/directoryservice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def self.get_password(guid, username)
264264
# string. The password_hash provided as a resource attribute is a
265265
# hex value. We need to convert the Base64 encoded string to a
266266
# hex value and provide it back to Puppet.
267-
converted_hash_plist['SALTED-SHA512'].unpack("H*")[0]
267+
converted_hash_plist['SALTED-SHA512'].unpack1("H*")
268268

269269
end
270270
end

lib/puppet/provider/user/directoryservice.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def self.convert_binary_to_hash(plist_data)
205205
# The salted-SHA512 password hash in 10.7 is stored in the 'SALTED-SHA512'
206206
# key as binary data. That data is extracted and converted to a hex string.
207207
def self.get_salted_sha512(embedded_binary_plist)
208-
embedded_binary_plist['SALTED-SHA512'].unpack("H*")[0]
208+
embedded_binary_plist['SALTED-SHA512'].unpack1("H*")
209209
end
210210

211211
# This method reads the passed embedded_binary_plist hash and returns values
@@ -220,7 +220,7 @@ def self.get_salted_sha512_pbkdf2(field, embedded_binary_plist, user_name = "")
220220
raise Puppet::Error, "Invalid #{field} given for user #{user_name}"
221221
end
222222

223-
value.unpack('H*').first
223+
value.unpack1('H*')
224224
when 'iterations'
225225
Integer(embedded_binary_plist['SALTED-SHA512-PBKDF2'][field])
226226
else

0 commit comments

Comments
 (0)