archive-zip 0.12.0 → 0.13.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/NEWS.md +5 -0
- data/README.md +1 -1
- data/lib/archive/support/ioextensions.rb +5 -7
- data/lib/archive/support/iowindow.rb +34 -87
- data/lib/archive/support/stringio.rb +27 -0
- data/lib/archive/support/zlib.rb +0 -435
- data/lib/archive/zip/codec/deflate/reader.rb +187 -0
- data/lib/archive/zip/codec/deflate/writer.rb +209 -0
- data/lib/archive/zip/codec/deflate.rb +92 -244
- data/lib/archive/zip/codec/null_encryption.rb +4 -184
- data/lib/archive/zip/codec/store/reader.rb +97 -0
- data/lib/archive/zip/codec/store/writer.rb +78 -0
- data/lib/archive/zip/codec/store.rb +6 -231
- data/lib/archive/zip/codec/traditional_encryption/base.rb +85 -0
- data/lib/archive/zip/codec/traditional_encryption/reader.rb +65 -0
- data/lib/archive/zip/codec/traditional_encryption/writer.rb +71 -0
- data/lib/archive/zip/codec/traditional_encryption.rb +6 -360
- data/lib/archive/zip/dos_time.rb +103 -0
- data/lib/archive/zip/entry.rb +86 -70
- data/lib/archive/zip.rb +2 -5
- metadata +35 -227
- data/.yardopts +0 -1
- data/Rakefile +0 -247
- data/lib/archive/support/binary_stringio.rb +0 -30
- data/lib/archive/support/integer.rb +0 -13
- data/lib/archive/support/io-like.rb +0 -14
- data/lib/archive/support/time.rb +0 -119
- data/lib/archive/zip/version.rb +0 -6
- data/spec/archive/dos_time_spec.rb +0 -113
- data/spec/archive/zip/archive_spec.rb +0 -54
- data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +0 -44
- data/spec/archive/zip/codec/deflate/compress/close_spec.rb +0 -45
- data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +0 -23
- data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +0 -74
- data/spec/archive/zip/codec/deflate/compress/new_spec.rb +0 -39
- data/spec/archive/zip/codec/deflate/compress/open_spec.rb +0 -48
- data/spec/archive/zip/codec/deflate/compress/write_spec.rb +0 -111
- data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +0 -20
- data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +0 -34
- data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +0 -20
- data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +0 -74
- data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +0 -16
- data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +0 -29
- data/spec/archive/zip/codec/deflate/fixtures/classes.rb +0 -25
- data/spec/archive/zip/codec/deflate/fixtures/compressed_file.bin +0 -1
- data/spec/archive/zip/codec/deflate/fixtures/compressed_file_nocomp.bin +0 -0
- data/spec/archive/zip/codec/deflate/fixtures/raw_file.txt +0 -10
- data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +0 -34
- data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +0 -16
- data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +0 -29
- data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +0 -26
- data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +0 -27
- data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +0 -59
- data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +0 -23
- data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +0 -34
- data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +0 -16
- data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +0 -31
- data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +0 -28
- data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +0 -52
- data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +0 -31
- data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +0 -31
- data/spec/archive/zip/codec/null_encryption/fixtures/classes.rb +0 -12
- data/spec/archive/zip/codec/null_encryption/fixtures/raw_file.txt +0 -10
- data/spec/archive/zip/codec/store/compress/close_spec.rb +0 -34
- data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +0 -77
- data/spec/archive/zip/codec/store/compress/new_spec.rb +0 -16
- data/spec/archive/zip/codec/store/compress/open_spec.rb +0 -29
- data/spec/archive/zip/codec/store/compress/rewind_spec.rb +0 -28
- data/spec/archive/zip/codec/store/compress/seek_spec.rb +0 -52
- data/spec/archive/zip/codec/store/compress/tell_spec.rb +0 -31
- data/spec/archive/zip/codec/store/compress/write_spec.rb +0 -29
- data/spec/archive/zip/codec/store/decompress/close_spec.rb +0 -34
- data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +0 -75
- data/spec/archive/zip/codec/store/decompress/new_spec.rb +0 -16
- data/spec/archive/zip/codec/store/decompress/open_spec.rb +0 -29
- data/spec/archive/zip/codec/store/decompress/read_spec.rb +0 -26
- data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +0 -27
- data/spec/archive/zip/codec/store/decompress/seek_spec.rb +0 -59
- data/spec/archive/zip/codec/store/decompress/tell_spec.rb +0 -23
- data/spec/archive/zip/codec/store/fixtures/classes.rb +0 -12
- data/spec/archive/zip/codec/store/fixtures/raw_file.txt +0 -10
- data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +0 -53
- data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +0 -20
- data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +0 -43
- data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +0 -127
- data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +0 -36
- data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +0 -80
- data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +0 -27
- data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +0 -53
- data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +0 -20
- data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +0 -41
- data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +0 -39
- data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +0 -73
- data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +0 -40
- data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +0 -114
- data/spec/archive/zip/codec/traditional_encryption/fixtures/classes.rb +0 -27
- data/spec/archive/zip/codec/traditional_encryption/fixtures/encrypted_file.bin +0 -0
- data/spec/archive/zip/codec/traditional_encryption/fixtures/raw_file.txt +0 -10
- data/spec/binary_stringio/new_spec.rb +0 -40
- data/spec/binary_stringio/set_encoding_spec.rb +0 -17
- data/spec/ioextensions/read_exactly_spec.rb +0 -52
- data/spec/zlib/fixtures/classes.rb +0 -65
- data/spec/zlib/fixtures/compressed_file.bin +0 -1
- data/spec/zlib/fixtures/compressed_file_gzip.bin +0 -0
- data/spec/zlib/fixtures/compressed_file_huffman.bin +0 -2
- data/spec/zlib/fixtures/compressed_file_minmem.bin +0 -0
- data/spec/zlib/fixtures/compressed_file_minwin.bin +0 -1
- data/spec/zlib/fixtures/compressed_file_nocomp.bin +0 -0
- data/spec/zlib/fixtures/compressed_file_raw.bin +0 -1
- data/spec/zlib/fixtures/raw_file.txt +0 -10
- data/spec/zlib/zreader/checksum_spec.rb +0 -42
- data/spec/zlib/zreader/close_spec.rb +0 -16
- data/spec/zlib/zreader/compressed_size_spec.rb +0 -20
- data/spec/zlib/zreader/new_spec.rb +0 -43
- data/spec/zlib/zreader/open_spec.rb +0 -51
- data/spec/zlib/zreader/read_spec.rb +0 -58
- data/spec/zlib/zreader/rewind_spec.rb +0 -25
- data/spec/zlib/zreader/seek_spec.rb +0 -57
- data/spec/zlib/zreader/tell_spec.rb +0 -23
- data/spec/zlib/zreader/uncompressed_size_spec.rb +0 -20
- data/spec/zlib/zwriter/checksum_spec.rb +0 -43
- data/spec/zlib/zwriter/close_spec.rb +0 -16
- data/spec/zlib/zwriter/compressed_size_spec.rb +0 -21
- data/spec/zlib/zwriter/new_spec.rb +0 -66
- data/spec/zlib/zwriter/open_spec.rb +0 -70
- data/spec/zlib/zwriter/rewind_spec.rb +0 -28
- data/spec/zlib/zwriter/seek_spec.rb +0 -52
- data/spec/zlib/zwriter/tell_spec.rb +0 -31
- data/spec/zlib/zwriter/uncompressed_size_spec.rb +0 -21
- data/spec/zlib/zwriter/write_spec.rb +0 -28
@@ -1,53 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#close" do
|
11
|
-
it "closes the stream" do
|
12
|
-
d = Archive::Zip::Codec::TraditionalEncryption::Decrypt.new(
|
13
|
-
BinaryStringIO.new("\000" * 12),
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
)
|
17
|
-
d.close
|
18
|
-
d.closed?.must_equal(true)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "closes the delegate stream by default" do
|
22
|
-
delegate = MiniTest::Mock.new
|
23
|
-
delegate.expect(:read, "\000" * 12, [Integer])
|
24
|
-
delegate.expect(:close, nil)
|
25
|
-
d = Archive::Zip::Codec::TraditionalEncryption::Decrypt.new(
|
26
|
-
delegate,
|
27
|
-
TraditionalEncryptionSpecs.password,
|
28
|
-
TraditionalEncryptionSpecs.mtime
|
29
|
-
)
|
30
|
-
d.close
|
31
|
-
end
|
32
|
-
|
33
|
-
it "optionally leaves the delegate stream open" do
|
34
|
-
delegate = MiniTest::Mock.new
|
35
|
-
delegate.expect(:read, "\000" * 12, [Integer])
|
36
|
-
delegate.expect(:close, nil)
|
37
|
-
d = Archive::Zip::Codec::TraditionalEncryption::Decrypt.new(
|
38
|
-
delegate,
|
39
|
-
TraditionalEncryptionSpecs.password,
|
40
|
-
TraditionalEncryptionSpecs.mtime
|
41
|
-
)
|
42
|
-
d.close(true)
|
43
|
-
|
44
|
-
delegate = MiniTest::Mock.new
|
45
|
-
delegate.expect(:read, "\000" * 12, [Integer])
|
46
|
-
d = Archive::Zip::Codec::TraditionalEncryption::Decrypt.new(
|
47
|
-
delegate,
|
48
|
-
TraditionalEncryptionSpecs.password,
|
49
|
-
TraditionalEncryptionSpecs.mtime
|
50
|
-
)
|
51
|
-
d.close(false)
|
52
|
-
end
|
53
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt.new" do
|
11
|
-
it "returns a new instance" do
|
12
|
-
d = Archive::Zip::Codec::TraditionalEncryption::Decrypt.new(
|
13
|
-
BinaryStringIO.new("\000" * 12),
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
)
|
17
|
-
d.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Decrypt)
|
18
|
-
d.close
|
19
|
-
end
|
20
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt.open" do
|
11
|
-
it "returns a new instance when run without a block" do
|
12
|
-
d = Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
13
|
-
BinaryStringIO.new("\000" * 12),
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
)
|
17
|
-
d.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Decrypt)
|
18
|
-
d.close
|
19
|
-
end
|
20
|
-
|
21
|
-
it "executes a block with a new instance as an argument" do
|
22
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
23
|
-
BinaryStringIO.new("\000" * 12),
|
24
|
-
TraditionalEncryptionSpecs.password,
|
25
|
-
TraditionalEncryptionSpecs.mtime
|
26
|
-
) do |decryptor|
|
27
|
-
decryptor.must_be_instance_of(
|
28
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt
|
29
|
-
)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it "closes the object after executing a block" do
|
34
|
-
d = Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
35
|
-
BinaryStringIO.new("\000" * 12),
|
36
|
-
TraditionalEncryptionSpecs.password,
|
37
|
-
TraditionalEncryptionSpecs.mtime
|
38
|
-
) do |decryptor|
|
39
|
-
decryptor
|
40
|
-
end
|
41
|
-
d.closed?.must_equal(true)
|
42
|
-
end
|
43
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
|
9
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#read" do
|
10
|
-
it "calls the read method of the delegate" do
|
11
|
-
delegate = MiniTest::Mock.new
|
12
|
-
delegate.expect(:read, "\000" * 12, [Integer])
|
13
|
-
delegate.expect(:read, nil, [Integer])
|
14
|
-
delegate.expect(:close, nil)
|
15
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
16
|
-
delegate,
|
17
|
-
TraditionalEncryptionSpecs.password,
|
18
|
-
TraditionalEncryptionSpecs.mtime
|
19
|
-
) do |d|
|
20
|
-
d.read
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "decrypts data read from the delegate" do
|
25
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
26
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
27
|
-
ed,
|
28
|
-
TraditionalEncryptionSpecs.password,
|
29
|
-
TraditionalEncryptionSpecs.mtime
|
30
|
-
) do |d|
|
31
|
-
d.read.must_equal(TraditionalEncryptionSpecs.test_data)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "decrypts data read from a delegate that only returns 1 byte at a time" do
|
37
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
38
|
-
# Override ed.read to raise Errno::EAGAIN every other time it's called.
|
39
|
-
class << ed
|
40
|
-
alias :read_orig :read
|
41
|
-
def read(length = nil, buffer = nil)
|
42
|
-
read_orig(1, buffer)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
47
|
-
ed,
|
48
|
-
TraditionalEncryptionSpecs.password,
|
49
|
-
TraditionalEncryptionSpecs.mtime
|
50
|
-
) do |d|
|
51
|
-
buffer = ''
|
52
|
-
begin
|
53
|
-
buffer << d.read
|
54
|
-
rescue Errno::EAGAIN
|
55
|
-
retry
|
56
|
-
end
|
57
|
-
buffer.must_equal(TraditionalEncryptionSpecs.test_data)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "decrypts data read from a delegate that raises Errno::EAGAIN" do
|
63
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
64
|
-
# Override ed.read to raise Errno::EAGAIN every other time it's called.
|
65
|
-
class << ed
|
66
|
-
alias :read_orig :read
|
67
|
-
def read(length = nil, buffer = nil)
|
68
|
-
@error_raised ||= false
|
69
|
-
if @error_raised then
|
70
|
-
@error_raised = false
|
71
|
-
read_orig(length, buffer)
|
72
|
-
else
|
73
|
-
@error_raised = true
|
74
|
-
raise Errno::EAGAIN
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
80
|
-
ed,
|
81
|
-
TraditionalEncryptionSpecs.password,
|
82
|
-
TraditionalEncryptionSpecs.mtime
|
83
|
-
) do |d|
|
84
|
-
buffer = ''
|
85
|
-
begin
|
86
|
-
buffer << d.read
|
87
|
-
rescue Errno::EAGAIN
|
88
|
-
retry
|
89
|
-
end
|
90
|
-
buffer.must_equal(TraditionalEncryptionSpecs.test_data)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
it "decrypts data read from a delegate that raises Errno::EINTR" do
|
96
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
97
|
-
# Override ed.read to raise Errno::EINTR every other time it's called.
|
98
|
-
class << ed
|
99
|
-
alias :read_orig :read
|
100
|
-
def read(length = nil, buffer = nil)
|
101
|
-
@error_raised ||= false
|
102
|
-
if @error_raised then
|
103
|
-
@error_raised = false
|
104
|
-
read_orig(length, buffer)
|
105
|
-
else
|
106
|
-
@error_raised = true
|
107
|
-
raise Errno::EINTR
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
113
|
-
ed,
|
114
|
-
TraditionalEncryptionSpecs.password,
|
115
|
-
TraditionalEncryptionSpecs.mtime
|
116
|
-
) do |d|
|
117
|
-
buffer = ''
|
118
|
-
begin
|
119
|
-
buffer << d.read
|
120
|
-
rescue Errno::EINTR
|
121
|
-
retry
|
122
|
-
end
|
123
|
-
buffer.must_equal(TraditionalEncryptionSpecs.test_data)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
|
9
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#rewind" do
|
10
|
-
it "can rewind the stream when the delegate responds to rewind" do
|
11
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
12
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
13
|
-
ed,
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
) do |d|
|
17
|
-
d.read(4)
|
18
|
-
d.rewind
|
19
|
-
d.read.must_equal(TraditionalEncryptionSpecs.test_data)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
25
|
-
delegate = MiniTest::Mock.new
|
26
|
-
delegate.expect(:read, "\000" * 12, [Integer])
|
27
|
-
delegate.expect(:close, nil)
|
28
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
29
|
-
delegate,
|
30
|
-
TraditionalEncryptionSpecs.password,
|
31
|
-
TraditionalEncryptionSpecs.mtime
|
32
|
-
) do |d|
|
33
|
-
lambda { d.rewind }.must_raise(Errno::EINVAL)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
|
9
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#seek" do
|
10
|
-
it "can seek to the beginning of the stream when the delegate responds to rewind" do
|
11
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
12
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
13
|
-
ed,
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
) do |d|
|
17
|
-
d.read(4)
|
18
|
-
d.seek(0).must_equal(0)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
|
24
|
-
delegate = MiniTest::Mock.new
|
25
|
-
delegate.expect(:read, "\000" * 12, [Integer])
|
26
|
-
delegate.expect(:close, nil)
|
27
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
28
|
-
delegate,
|
29
|
-
TraditionalEncryptionSpecs.password,
|
30
|
-
TraditionalEncryptionSpecs.mtime
|
31
|
-
) do |d|
|
32
|
-
lambda { d.seek(0) }.must_raise(Errno::EINVAL)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "raises Errno::EINVAL when seeking forward or backward from the current position of the stream" do
|
37
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
38
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
39
|
-
ed,
|
40
|
-
TraditionalEncryptionSpecs.password,
|
41
|
-
TraditionalEncryptionSpecs.mtime
|
42
|
-
) do |d|
|
43
|
-
# Disable read buffering to avoid some seeking optimizations implemented
|
44
|
-
# by IO::Like which allow seeking forward within the buffer.
|
45
|
-
d.fill_size = 0
|
46
|
-
|
47
|
-
d.read(4)
|
48
|
-
lambda { d.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
49
|
-
lambda { d.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
55
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
56
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
57
|
-
ed,
|
58
|
-
TraditionalEncryptionSpecs.password,
|
59
|
-
TraditionalEncryptionSpecs.mtime
|
60
|
-
) do |d|
|
61
|
-
lambda { d.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
62
|
-
lambda { d.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
68
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
69
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
70
|
-
ed,
|
71
|
-
TraditionalEncryptionSpecs.password,
|
72
|
-
TraditionalEncryptionSpecs.mtime
|
73
|
-
) do |d|
|
74
|
-
lambda { d.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
75
|
-
lambda { d.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
76
|
-
lambda { d.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
|
9
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Decrypt#tell" do
|
10
|
-
it "returns the current position of the stream" do
|
11
|
-
TraditionalEncryptionSpecs.encrypted_data do |ed|
|
12
|
-
Archive::Zip::Codec::TraditionalEncryption::Decrypt.open(
|
13
|
-
ed,
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
) do |d|
|
17
|
-
d.tell.must_equal(0)
|
18
|
-
d.read(4)
|
19
|
-
d.tell.must_equal(4)
|
20
|
-
d.read
|
21
|
-
d.tell.must_equal(235)
|
22
|
-
d.rewind
|
23
|
-
d.tell.must_equal(0)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#close" do
|
11
|
-
it "closes the stream" do
|
12
|
-
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
13
|
-
BinaryStringIO.new,
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
)
|
17
|
-
e.close
|
18
|
-
e.closed?.must_equal(true)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "closes the delegate stream by default" do
|
22
|
-
delegate = MiniTest::Mock.new
|
23
|
-
delegate.expect(:write, 12, [String])
|
24
|
-
delegate.expect(:close, nil)
|
25
|
-
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
26
|
-
delegate,
|
27
|
-
TraditionalEncryptionSpecs.password,
|
28
|
-
TraditionalEncryptionSpecs.mtime
|
29
|
-
)
|
30
|
-
e.close
|
31
|
-
end
|
32
|
-
|
33
|
-
it "optionally leaves the delegate stream open" do
|
34
|
-
delegate = MiniTest::Mock.new
|
35
|
-
delegate.expect(:write, 12, [String])
|
36
|
-
delegate.expect(:close, nil)
|
37
|
-
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
38
|
-
delegate,
|
39
|
-
TraditionalEncryptionSpecs.password,
|
40
|
-
TraditionalEncryptionSpecs.mtime
|
41
|
-
)
|
42
|
-
e.close(true)
|
43
|
-
|
44
|
-
delegate = MiniTest::Mock.new
|
45
|
-
delegate.expect(:write, 12, [String])
|
46
|
-
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
47
|
-
delegate,
|
48
|
-
TraditionalEncryptionSpecs.password,
|
49
|
-
TraditionalEncryptionSpecs.mtime
|
50
|
-
)
|
51
|
-
e.close(false)
|
52
|
-
end
|
53
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt.new" do
|
11
|
-
it "returns a new instance" do
|
12
|
-
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.new(
|
13
|
-
BinaryStringIO.new,
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
)
|
17
|
-
e.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Encrypt)
|
18
|
-
e.close
|
19
|
-
end
|
20
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt.open" do
|
11
|
-
it "returns a new instance when run without a block" do
|
12
|
-
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
13
|
-
BinaryStringIO.new,
|
14
|
-
TraditionalEncryptionSpecs.password,
|
15
|
-
TraditionalEncryptionSpecs.mtime
|
16
|
-
)
|
17
|
-
e.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Encrypt)
|
18
|
-
e.close
|
19
|
-
end
|
20
|
-
|
21
|
-
it "executes a block with a new instance as an argument" do
|
22
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
23
|
-
BinaryStringIO.new,
|
24
|
-
TraditionalEncryptionSpecs.password,
|
25
|
-
TraditionalEncryptionSpecs.mtime
|
26
|
-
) do |encryptor|
|
27
|
-
encryptor.must_be_instance_of(Archive::Zip::Codec::TraditionalEncryption::Encrypt)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "closes the object after executing a block" do
|
32
|
-
e = Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
33
|
-
BinaryStringIO.new,
|
34
|
-
TraditionalEncryptionSpecs.password,
|
35
|
-
TraditionalEncryptionSpecs.mtime
|
36
|
-
) do |encryptor|
|
37
|
-
encryptor
|
38
|
-
end
|
39
|
-
e.closed?.must_equal(true)
|
40
|
-
end
|
41
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#rewind" do
|
11
|
-
it "can rewind the stream when the delegate responds to rewind" do
|
12
|
-
encrypted_data = BinaryStringIO.new
|
13
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
14
|
-
encrypted_data,
|
15
|
-
TraditionalEncryptionSpecs.password,
|
16
|
-
TraditionalEncryptionSpecs.mtime
|
17
|
-
) do |e|
|
18
|
-
e.write('test')
|
19
|
-
# Ensure repeatable test data is used for encryption header.
|
20
|
-
srand(0)
|
21
|
-
e.rewind
|
22
|
-
e.write(TraditionalEncryptionSpecs.test_data)
|
23
|
-
end
|
24
|
-
encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
|
28
|
-
delegate = MiniTest::Mock.new
|
29
|
-
delegate.expect(:write, 12, [String])
|
30
|
-
delegate.expect(:close, nil)
|
31
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
32
|
-
delegate,
|
33
|
-
TraditionalEncryptionSpecs.password,
|
34
|
-
TraditionalEncryptionSpecs.mtime
|
35
|
-
) do |e|
|
36
|
-
lambda { e.rewind }.must_raise(Errno::EINVAL)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#seek" do
|
11
|
-
it "can seek to the beginning of the stream when the delegate responds to rewind" do
|
12
|
-
encrypted_data = BinaryStringIO.new
|
13
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
14
|
-
encrypted_data,
|
15
|
-
TraditionalEncryptionSpecs.password,
|
16
|
-
TraditionalEncryptionSpecs.mtime
|
17
|
-
) do |e|
|
18
|
-
e.write('test')
|
19
|
-
e.seek(0).must_equal(0)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
|
24
|
-
delegate = MiniTest::Mock.new
|
25
|
-
delegate.expect(:write, 12, [String])
|
26
|
-
delegate.expect(:close, nil)
|
27
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
28
|
-
delegate,
|
29
|
-
TraditionalEncryptionSpecs.password,
|
30
|
-
TraditionalEncryptionSpecs.mtime
|
31
|
-
) do |e|
|
32
|
-
lambda { e.seek(0) }.must_raise(Errno::EINVAL)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "raises Errno::EINVAL when seeking forward or backward from the current position of the stream" do
|
37
|
-
encrypted_data = BinaryStringIO.new
|
38
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
39
|
-
encrypted_data,
|
40
|
-
TraditionalEncryptionSpecs.password,
|
41
|
-
TraditionalEncryptionSpecs.mtime
|
42
|
-
) do |e|
|
43
|
-
e.write('test')
|
44
|
-
lambda { e.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
45
|
-
lambda { e.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
|
50
|
-
encrypted_data = BinaryStringIO.new
|
51
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
52
|
-
encrypted_data,
|
53
|
-
TraditionalEncryptionSpecs.password,
|
54
|
-
TraditionalEncryptionSpecs.mtime
|
55
|
-
) do |e|
|
56
|
-
lambda { e.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
57
|
-
lambda { e.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it "raises Errno::EINVAL when seeking relative to the end of the stream" do
|
62
|
-
encrypted_data = BinaryStringIO.new
|
63
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
64
|
-
encrypted_data,
|
65
|
-
TraditionalEncryptionSpecs.password,
|
66
|
-
TraditionalEncryptionSpecs.mtime
|
67
|
-
) do |e|
|
68
|
-
lambda { e.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
69
|
-
lambda { e.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
70
|
-
lambda { e.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
|
5
|
-
require File.expand_path('../../fixtures/classes', __FILE__)
|
6
|
-
|
7
|
-
require 'archive/zip/codec/traditional_encryption'
|
8
|
-
require 'archive/support/binary_stringio'
|
9
|
-
|
10
|
-
describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#tell" do
|
11
|
-
it "returns the current position of the stream" do
|
12
|
-
encrypted_data = BinaryStringIO.new
|
13
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
14
|
-
encrypted_data,
|
15
|
-
TraditionalEncryptionSpecs.password,
|
16
|
-
TraditionalEncryptionSpecs.mtime
|
17
|
-
) do |e|
|
18
|
-
e.tell.must_equal(0)
|
19
|
-
e.write('test1')
|
20
|
-
e.tell.must_equal(5)
|
21
|
-
e.write('test2')
|
22
|
-
e.tell.must_equal(10)
|
23
|
-
e.rewind
|
24
|
-
e.tell.must_equal(0)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "raises IOError on closed stream" do
|
29
|
-
delegate = MiniTest::Mock.new
|
30
|
-
delegate.expect(:write, 12, [String])
|
31
|
-
delegate.expect(:close, nil)
|
32
|
-
lambda do
|
33
|
-
Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
|
34
|
-
delegate,
|
35
|
-
TraditionalEncryptionSpecs.password,
|
36
|
-
TraditionalEncryptionSpecs.mtime
|
37
|
-
) { |e| e }.tell
|
38
|
-
end.must_raise(IOError)
|
39
|
-
end
|
40
|
-
end
|