archive-zip 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -6,7 +6,18 @@ detailed information is available in the rest of the documentation.
6
6
  <b>NOTE:</b> Date stamps in the following entries are in YYYY/MM/DD format.
7
7
 
8
8
 
9
- == v0.4.0 (2011/??/??)
9
+ == v0.5.0 (2012/03/01)
10
+
11
+ === Fixes
12
+
13
+ * Avoid timezone discrepancies in encryption tests.
14
+ * Moved the DOSTime class to the Archive namespace (Chris Schneider).
15
+
16
+ === Notes
17
+
18
+ * Broke backward compatibility of the DOSTime class.
19
+
20
+ == v0.4.0 (2011/08/29)
10
21
 
11
22
  === Features
12
23
 
data/Rakefile CHANGED
@@ -75,6 +75,8 @@ PKG_FILES = FileList.new('**/*', '**/.[^.][^.]*') do |files|
75
75
  files.exclude('**/.*.sw?')
76
76
  # Exclude Git administrative files and directories.
77
77
  files.exclude(%r{(^|[/\\])\.git(ignore|modules)?([/\\]|$)})
78
+ # Exclude Rubunius compiled Ruby files.
79
+ files.exclude('**/*.rbc')
78
80
 
79
81
  # Exclude the top level pkg, doc, and examples directories and their contents.
80
82
  files.exclude(%r{^(pkg|doc|examples)([/\\]|$)})
@@ -14,7 +14,7 @@ class Time
14
14
  dos_year = 0 if dos_year < 0
15
15
  dos_year = 119 if dos_year > 119
16
16
 
17
- DOSTime.new(
17
+ Archive::DOSTime.new(
18
18
  (dos_sec ) |
19
19
  (min << 5) |
20
20
  (hour << 11) |
@@ -27,61 +27,64 @@ end
27
27
 
28
28
  # A representation of the DOS time structure which can be converted into
29
29
  # instances of Time.
30
- class DOSTime
31
- include Comparable
30
+ module Archive
31
+ class DOSTime
32
+ include Comparable
32
33
 
33
- # Creates a new instance of DOSTime. _dos_time_ is a 4 byte String or
34
- # unsigned number (Integer) representing an MS-DOS time structure where:
35
- # Bits 0-4:: 2 second increments (0-29)
36
- # Bits 5-10:: minutes (0-59)
37
- # Bits 11-15:: hours (0-24)
38
- # Bits 16-20:: day (1-31)
39
- # Bits 21-24:: month (1-12)
40
- # Bits 25-31:: four digit year minus 1980 (0-119)
41
- #
42
- # If _dos_time_ is ommitted or +nil+, a new instance is created based on the
43
- # current time.
44
- def initialize(dos_time = nil)
45
- case dos_time
46
- when nil
47
- @dos_time = Time.now.to_dos_time.dos_time
48
- when Integer
49
- @dos_time = dos_time
50
- else
51
- unless dos_time.length == 4 then
52
- raise ArgumentError, 'length of DOS time structure is not 4'
34
+ # Creates a new instance of DOSTime. _dos_time_ is a 4 byte String or
35
+ # unsigned number (Integer) representing an MS-DOS time structure where:
36
+ # Bits 0-4:: 2 second increments (0-29)
37
+ # Bits 5-10:: minutes (0-59)
38
+ # Bits 11-15:: hours (0-24)
39
+ # Bits 16-20:: day (1-31)
40
+ # Bits 21-24:: month (1-12)
41
+ # Bits 25-31:: four digit year minus 1980 (0-119)
42
+ #
43
+ # If _dos_time_ is ommitted or +nil+, a new instance is created based on the
44
+ # current time.
45
+ def initialize(dos_time = nil)
46
+ case dos_time
47
+ when nil
48
+ @dos_time = Time.now.to_dos_time.dos_time
49
+ when Integer
50
+ @dos_time = dos_time
51
+ else
52
+ unless dos_time.length == 4 then
53
+ raise ArgumentError, 'length of DOS time structure is not 4'
54
+ end
55
+ @dos_time = dos_time.unpack('V')[0]
53
56
  end
54
- @dos_time = dos_time.unpack('V')[0]
55
57
  end
56
- end
57
-
58
- # Returns -1 if _other_ is a time earlier than this one, 0 if _other_ is the
59
- # same time, and 1 if _other_ is a later time.
60
- def cmp(other)
61
- @dos_time <=> other.dos_time
62
- end
63
- alias :<=> :cmp
64
58
 
65
- # Returns the time value of this object as an integer representing the DOS
66
- # time structure.
67
- def to_i
68
- @dos_time
69
- end
59
+ # Returns -1 if _other_ is a time earlier than this one, 0 if _other_ is the
60
+ # same time, and 1 if _other_ is a later time.
61
+ def cmp(other)
62
+ to_i <=> other.to_i
63
+ end
64
+ alias :<=> :cmp
70
65
 
71
- # Returns a Time instance which is equivalent to the time represented by this
72
- # object.
73
- def to_time
74
- second = ((0b11111 & @dos_time) ) * 2
75
- minute = ((0b111111 << 5 & @dos_time) >> 5)
76
- hour = ((0b11111 << 11 & @dos_time) >> 11)
77
- day = ((0b11111 << 16 & @dos_time) >> 16)
78
- month = ((0b1111 << 21 & @dos_time) >> 21)
79
- year = ((0b1111111 << 25 & @dos_time) >> 25) + 1980
80
- return Time.local(year, month, day, hour, minute, second)
81
- end
66
+ # Returns the time value of this object as an integer representing the DOS
67
+ # time structure.
68
+ def to_i
69
+ @dos_time
70
+ end
82
71
 
83
- protected
72
+ # Returns the 32 bit integer that backs this object packed into a String in
73
+ # little endian format. This is suitable for use with #new.
74
+ def pack
75
+ [to_i].pack('V')
76
+ end
84
77
 
85
- # Used by _cmp_ to read another time stored in another DOSTime instance.
86
- attr_reader :dos_time # :nodoc:
78
+ # Returns a Time instance which is equivalent to the time represented by
79
+ # this object.
80
+ def to_time
81
+ second = ((0b11111 & @dos_time) ) * 2
82
+ minute = ((0b111111 << 5 & @dos_time) >> 5)
83
+ hour = ((0b11111 << 11 & @dos_time) >> 11)
84
+ day = ((0b11111 << 16 & @dos_time) >> 16)
85
+ month = ((0b1111 << 21 & @dos_time) >> 21)
86
+ year = ((0b1111111 << 25 & @dos_time) >> 25) + 1980
87
+ return Time.local(year, month, day, hour, minute, second)
88
+ end
89
+ end
87
90
  end
@@ -58,13 +58,9 @@ module Archive; class Zip; module Codec
58
58
  # flipped before processing. The new CRC value must have its bits
59
59
  # flipped as well for storage and later use. This applies to the
60
60
  # handling of @key0 and @key2.
61
- #
62
- # NOTE: XOR'ing with 0xffffffff is used instead of simple bit negation
63
- # in case this is run on a platform with a native integer size of
64
- # something other than 32 bits.
65
- @key0 = Zlib.crc32(char, @key0 ^ 0xffffffff) ^ 0xffffffff
61
+ @key0 = ~Zlib.crc32(char, ~@key0)
66
62
  @key1 = ((@key1 + (@key0 & 0xff)) * 134775813 + 1) & 0xffffffff
67
- @key2 = Zlib.crc32((@key1 >> 24).chr, @key2 ^ 0xffffffff) ^ 0xffffffff
63
+ @key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2)
68
64
  nil
69
65
  end
70
66
 
@@ -157,14 +153,13 @@ module Archive; class Zip; module Codec
157
153
 
158
154
  # Create and encrypt a 12 byte header to protect the encrypted file data
159
155
  # from attack. The first 10 bytes are random, and the last 2 bytes are
160
- # the low order word of the last modified time of the entry in DOS
161
- # format.
156
+ # the low order word in little endian byte order of the last modified
157
+ # time of the entry in DOS format.
162
158
  header = ''
163
159
  10.times do
164
160
  header << rand(256).chr
165
161
  end
166
- time = mtime.to_dos_time.to_i
167
- header << (time & 0xff).chr << ((time >> 8) & 0xff).chr
162
+ header << mtime.to_dos_time.pack[0, 2]
168
163
 
169
164
  # Take care to ensure that all bytes in the header are written.
170
165
  while header.size > 0 do
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Archive; class Zip
4
4
  # The current version of this gem.
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end; end
@@ -7,7 +7,7 @@ class TraditionalEncryptionSpecs
7
7
  end
8
8
 
9
9
  def mtime
10
- Time.at(0)
10
+ Time.local(1979, 12, 31, 18, 0, 0)
11
11
  end
12
12
 
13
13
  def encrypted_data
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archive-zip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-30 00:00:00.000000000Z
12
+ date: 2012-03-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: io-like
16
- requirement: &19530420 !ruby/object:Gem::Requirement
16
+ requirement: &12753840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19530420
24
+ version_requirements: *12753840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &19529560 !ruby/object:Gem::Requirement
27
+ requirement: &12752440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *19529560
35
+ version_requirements: *12752440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mspec
38
- requirement: &19528860 !ruby/object:Gem::Requirement
38
+ requirement: &12750780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.5.12
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *19528860
46
+ version_requirements: *12750780
47
47
  description: ! 'Archive::Zip provides a simple Ruby-esque interface to creating, extracting,
48
48
  and
49
49
 
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  version: '0'
213
213
  requirements: []
214
214
  rubyforge_project: archive-zip
215
- rubygems_version: 1.8.8
215
+ rubygems_version: 1.8.10
216
216
  signing_key:
217
217
  specification_version: 3
218
218
  summary: Simple, extensible, pure Ruby ZIP archive support.