solaris-contents 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -204,10 +204,13 @@ module Solaris
204
204
  end
205
205
 
206
206
  # Return the sum of the byte values of the file, modulo 65535. This is
207
- # the value returned by Solaris' sum(1) (NB. not cksum(1) or sum(1B)).
207
+ # the value returned by Solaris' sum(1) and based on the ATT SysV
208
+ # algorithm (NB. not cksum(1) or sum(1B) or the sum(1) BSD algorithm).
208
209
  # This is a weak checksum and should not be used for security purposes.
209
210
  def self.sum(io_or_string)
210
- io_or_string.each_byte.inject { |r, v| ( r + v ) & 0xffff }
211
+ s = io_or_string.each_byte.inject { |r, v| (r + v) & 0xffffffff }
212
+ r = (s & 0xffff) + ((s & 0xffffffff) >> 16)
213
+ (r & 0xffff) + (r >> 16)
211
214
  end
212
215
 
213
216
  # Create a new contents(4) object.
@@ -12,8 +12,8 @@ class TestContents < Test::Unit::TestCase #:nodoc:
12
12
  assert_equal( 128, Solaris::Contents.sum( '@@' ) )
13
13
  assert_equal( 64_000, Solaris::Contents.sum( '@' * 1_000 ) )
14
14
  assert_equal( 65_472, Solaris::Contents.sum( '@' * 1_023 ) )
15
- assert_equal( 0, Solaris::Contents.sum( '@' * 1_024 ) )
16
- assert_equal( 64, Solaris::Contents.sum( '@' * 1_025 ) )
15
+ assert_equal( 1, Solaris::Contents.sum( '@' * 1_024 ) )
16
+ assert_equal( 65, Solaris::Contents.sum( '@' * 1_025 ) )
17
17
  end
18
18
 
19
19
  def test_sum_from_io
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solaris-contents
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000 Z
12
+ date: 2012-06-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Parse and write Solaris package contents records
15
15
  email: mcarpenter@free.fr