rubyzip 0.9.9 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +284 -41
- data/Rakefile +11 -6
- data/TODO +0 -1
- data/lib/zip/central_directory.rb +208 -0
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +59 -7
- data/lib/zip/crypto/encryption.rb +11 -0
- data/lib/zip/crypto/null_encryption.rb +43 -0
- data/lib/zip/crypto/traditional_encryption.rb +99 -0
- data/lib/zip/decompressor.rb +4 -4
- data/lib/zip/deflater.rb +17 -13
- data/lib/zip/dos_time.rb +13 -14
- data/lib/zip/entry.rb +700 -0
- data/lib/zip/entry_set.rb +86 -0
- data/lib/zip/errors.rb +18 -0
- data/lib/zip/extra_field/generic.rb +43 -0
- data/lib/zip/extra_field/ntfs.rb +90 -0
- data/lib/zip/extra_field/old_unix.rb +44 -0
- data/lib/zip/extra_field/universal_time.rb +47 -0
- data/lib/zip/extra_field/unix.rb +37 -0
- data/lib/zip/extra_field/zip64.rb +68 -0
- data/lib/zip/extra_field/zip64_placeholder.rb +15 -0
- data/lib/zip/extra_field.rb +101 -0
- data/lib/zip/file.rb +443 -0
- data/lib/zip/{zipfilesystem.rb → filesystem.rb} +162 -157
- data/lib/zip/inflater.rb +29 -28
- data/lib/zip/input_stream.rb +173 -0
- data/lib/zip/ioextras/abstract_input_stream.rb +111 -0
- data/lib/zip/ioextras/abstract_output_stream.rb +43 -0
- data/lib/zip/ioextras.rb +21 -149
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +8 -6
- data/lib/zip/null_input_stream.rb +3 -2
- data/lib/zip/output_stream.rb +189 -0
- data/lib/zip/pass_thru_compressor.rb +6 -6
- data/lib/zip/pass_thru_decompressor.rb +19 -19
- data/lib/zip/{zip_streamable_directory.rb → streamable_directory.rb} +3 -3
- data/lib/zip/streamable_stream.rb +56 -0
- data/lib/zip/version.rb +3 -0
- data/lib/zip.rb +71 -0
- data/samples/example.rb +44 -32
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +33 -28
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +26 -28
- data/samples/qtzip.rb +22 -31
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +31 -39
- data/test/basic_zip_file_test.rb +60 -0
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +69 -0
- data/test/central_directory_test.rb +100 -0
- data/test/crypto/null_encryption_test.rb +57 -0
- data/test/crypto/traditional_encryption_test.rb +80 -0
- data/test/data/WarnInvalidDate.zip +0 -0
- data/test/data/file1.txt +46 -0
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +1504 -0
- data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
- data/test/data/globTest/foo.txt +0 -0
- data/test/data/globTest/food.txt +0 -0
- data/test/data/globTest.zip +0 -0
- data/test/data/gpbit3stored.zip +0 -0
- data/test/data/mimetype +1 -0
- data/test/data/notzippedruby.rb +7 -0
- data/test/data/ntfs.zip +0 -0
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/path_traversal/Makefile +10 -0
- data/test/data/path_traversal/jwilk/README.md +5 -0
- data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
- data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
- data/test/data/path_traversal/jwilk/relative0.zip +0 -0
- data/test/data/path_traversal/jwilk/relative2.zip +0 -0
- data/test/data/path_traversal/jwilk/symlink.zip +0 -0
- data/test/data/path_traversal/relative1.zip +0 -0
- data/test/data/path_traversal/tilde.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/README.md +3 -0
- data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
- data/test/data/rubycode.zip +0 -0
- data/test/data/rubycode2.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/data/testDirectory.bin +0 -0
- data/test/data/zip64-sample.zip +0 -0
- data/test/data/zipWithDirs.zip +0 -0
- data/test/data/zipWithEncryption.zip +0 -0
- data/test/deflater_test.rb +65 -0
- data/test/encryption_test.rb +42 -0
- data/test/entry_set_test.rb +163 -0
- data/test/entry_test.rb +154 -0
- data/test/errors_test.rb +35 -0
- data/test/extra_field_test.rb +76 -0
- data/test/file_extract_directory_test.rb +54 -0
- data/test/file_extract_test.rb +145 -0
- data/test/file_permissions_test.rb +65 -0
- data/test/file_split_test.rb +57 -0
- data/test/file_test.rb +666 -0
- data/test/filesystem/dir_iterator_test.rb +58 -0
- data/test/filesystem/directory_test.rb +139 -0
- data/test/filesystem/file_mutating_test.rb +87 -0
- data/test/filesystem/file_nonmutating_test.rb +508 -0
- data/test/filesystem/file_stat_test.rb +64 -0
- data/test/gentestfiles.rb +126 -0
- data/test/inflater_test.rb +14 -0
- data/test/input_stream_test.rb +182 -0
- data/test/ioextras/abstract_input_stream_test.rb +102 -0
- data/test/ioextras/abstract_output_stream_test.rb +106 -0
- data/test/ioextras/fake_io_test.rb +18 -0
- data/test/local_entry_test.rb +154 -0
- data/test/output_stream_test.rb +128 -0
- data/test/pass_thru_compressor_test.rb +30 -0
- data/test/pass_thru_decompressor_test.rb +14 -0
- data/test/path_traversal_test.rb +141 -0
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +95 -0
- data/test/test_helper.rb +234 -0
- data/test/unicode_file_names_and_comments_test.rb +62 -0
- data/test/zip64_full_test.rb +51 -0
- data/test/zip64_support_test.rb +14 -0
- metadata +274 -41
- data/NEWS +0 -172
- data/lib/zip/settings.rb +0 -10
- data/lib/zip/tempfile_bugfixed.rb +0 -195
- data/lib/zip/zip.rb +0 -56
- data/lib/zip/zip_central_directory.rb +0 -135
- data/lib/zip/zip_entry.rb +0 -638
- data/lib/zip/zip_entry_set.rb +0 -77
- data/lib/zip/zip_extra_field.rb +0 -213
- data/lib/zip/zip_file.rb +0 -340
- data/lib/zip/zip_input_stream.rb +0 -144
- data/lib/zip/zip_output_stream.rb +0 -173
- data/lib/zip/zip_streamable_stream.rb +0 -47
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NullEncrypterTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@encrypter = ::Zip::NullEncrypter.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_header_bytesize
|
9
|
+
assert_equal 0, @encrypter.header_bytesize
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_gp_flags
|
13
|
+
assert_equal 0, @encrypter.gp_flags
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_header
|
17
|
+
assert_empty @encrypter.header(nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_encrypt
|
21
|
+
assert_nil @encrypter.encrypt(nil)
|
22
|
+
|
23
|
+
['', 'a' * 10, 0xffffffff].each do |data|
|
24
|
+
assert_equal data, @encrypter.encrypt(data)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_reset!
|
29
|
+
assert_respond_to @encrypter, :reset!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class NullDecrypterTest < MiniTest::Test
|
34
|
+
def setup
|
35
|
+
@decrypter = ::Zip::NullDecrypter.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_header_bytesize
|
39
|
+
assert_equal 0, @decrypter.header_bytesize
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_gp_flags
|
43
|
+
assert_equal 0, @decrypter.gp_flags
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_decrypt
|
47
|
+
assert_nil @decrypter.decrypt(nil)
|
48
|
+
|
49
|
+
['', 'a' * 10, 0xffffffff].each do |data|
|
50
|
+
assert_equal data, @decrypter.decrypt(data)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_reset!
|
55
|
+
assert_respond_to @decrypter, :reset!
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TraditionalEncrypterTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@mtime = ::Zip::DOSTime.new(2014, 12, 17, 15, 56, 24)
|
6
|
+
@encrypter = ::Zip::TraditionalEncrypter.new('password')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_header_bytesize
|
10
|
+
assert_equal 12, @encrypter.header_bytesize
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_gp_flags
|
14
|
+
assert_equal 9, @encrypter.gp_flags
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_header
|
18
|
+
@encrypter.reset!
|
19
|
+
exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*')
|
20
|
+
Random.stub(:rand, 1) do
|
21
|
+
assert_equal exepected, @encrypter.header(@mtime)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_encrypt
|
26
|
+
@encrypter.reset!
|
27
|
+
Random.stub(:rand, 1) { @encrypter.header(@mtime) }
|
28
|
+
assert_raises(NoMethodError) { @encrypter.encrypt(nil) }
|
29
|
+
assert_raises(NoMethodError) { @encrypter.encrypt(1) }
|
30
|
+
assert_equal '', @encrypter.encrypt('')
|
31
|
+
assert_equal [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].pack('C*'), @encrypter.encrypt('a' * 10)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_reset!
|
35
|
+
@encrypter.reset!
|
36
|
+
Random.stub(:rand, 1) { @encrypter.header(@mtime) }
|
37
|
+
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
38
|
+
assert_equal c, @encrypter.encrypt('a')
|
39
|
+
end
|
40
|
+
assert_equal 56.chr, @encrypter.encrypt('a')
|
41
|
+
@encrypter.reset!
|
42
|
+
Random.stub(:rand, 1) { @encrypter.header(@mtime) }
|
43
|
+
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
44
|
+
assert_equal c, @encrypter.encrypt('a')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class TraditionalDecrypterTest < MiniTest::Test
|
50
|
+
def setup
|
51
|
+
@decrypter = ::Zip::TraditionalDecrypter.new('password')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_header_bytesize
|
55
|
+
assert_equal 12, @decrypter.header_bytesize
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_gp_flags
|
59
|
+
assert_equal 9, @decrypter.gp_flags
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_decrypt
|
63
|
+
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
|
64
|
+
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
65
|
+
assert_equal 'a', @decrypter.decrypt(c)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_reset!
|
70
|
+
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
|
71
|
+
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
72
|
+
assert_equal 'a', @decrypter.decrypt(c)
|
73
|
+
end
|
74
|
+
assert_equal 91.chr, @decrypter.decrypt(2.chr)
|
75
|
+
@decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
|
76
|
+
[100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
|
77
|
+
assert_equal 'a', @decrypter.decrypt(c)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
Binary file
|
data/test/data/file1.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
AUTOMAKE_OPTIONS = gnu
|
3
|
+
|
4
|
+
EXTRA_DIST = test.zip
|
5
|
+
|
6
|
+
CXXFLAGS= -g
|
7
|
+
|
8
|
+
noinst_LIBRARIES = libzipios.a
|
9
|
+
|
10
|
+
bin_PROGRAMS = test_zip test_izipfilt test_izipstream
|
11
|
+
# test_flist
|
12
|
+
|
13
|
+
libzipios_a_SOURCES = backbuffer.h fcol.cpp fcol.h \
|
14
|
+
fcol_common.h fcolexceptions.cpp fcolexceptions.h \
|
15
|
+
fileentry.cpp fileentry.h flist.cpp \
|
16
|
+
flist.h flistentry.cpp flistentry.h \
|
17
|
+
flistscanner.h ifiltstreambuf.cpp ifiltstreambuf.h \
|
18
|
+
inflatefilt.cpp inflatefilt.h izipfilt.cpp \
|
19
|
+
izipfilt.h izipstream.cpp izipstream.h \
|
20
|
+
zipfile.cpp zipfile.h ziphead.cpp \
|
21
|
+
ziphead.h flistscanner.ll
|
22
|
+
|
23
|
+
# test_flist_SOURCES = test_flist.cpp
|
24
|
+
|
25
|
+
test_izipfilt_SOURCES = test_izipfilt.cpp
|
26
|
+
|
27
|
+
test_izipstream_SOURCES = test_izipstream.cpp
|
28
|
+
|
29
|
+
test_zip_SOURCES = test_zip.cpp
|
30
|
+
|
31
|
+
# Notice that libzipios.a is not specified as -L. -lzipios
|
32
|
+
# If it was, automake would not include it as a dependency.
|
33
|
+
|
34
|
+
# test_flist_LDADD = libzipios.a
|
35
|
+
|
36
|
+
test_izipfilt_LDADD = libzipios.a -lz
|
37
|
+
|
38
|
+
test_zip_LDADD = libzipios.a -lz
|
39
|
+
|
40
|
+
test_izipstream_LDADD = libzipios.a -lz
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
flistscanner.cc : flistscanner.ll
|
45
|
+
$(LEX) -+ -PFListScanner -o$@ $^
|
46
|
+
|
Binary file
|