(void)rounds; /* UNUSED */
(void)derived_key; /* UNUSED */
(void)derived_key_len; /* UNUSED */
- return -1; /* UNSUPPORTED */
+ return CRYPTOR_STUB_FUNCTION; /* UNSUPPORTED */
}
#endif
(void)ctx; /* UNUSED */
(void)key; /* UNUSED */
(void)key_len; /* UNUSED */
- return -1;
+ return CRYPTOR_STUB_FUNCTION;
}
static int
aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
{
(void)ctx; /* UNUSED */
- return -1;
+ return CRYPTOR_STUB_FUNCTION;
}
static int
(void)out; /* UNUSED */
(void)out_len; /* UNUSED */
aes_ctr_encrypt_counter(ctx); /* UNUSED */ /* Fix unused function warning */
- return -1;
+ return CRYPTOR_STUB_FUNCTION;
}
#else
#define archive_encrypto_aes_ctr_release(ctx) \
__archive_cryptor.encrypto_aes_ctr_release(ctx)
+/* Stub return value if no encryption support exists. */
+#define CRYPTOR_STUB_FUNCTION -2
+
/* Minimal interface to cryptographic functionality for internal use in
* libarchive */
struct archive_cryptor
p, salt_len, 1000, derived_key, key_len * 2 + 2);
if (r != 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Decryption is unsupported due to lack of "
- "crypto library");
+ r == CRYPTOR_STUB_FUNCTION ? "Decryption is unsupported due "
+ "to lack of crypto library" : "Failed to process passphrase");
return (ARCHIVE_FAILED);
}
"Can't generate random number for encryption");
return (ARCHIVE_FATAL);
}
- archive_pbkdf2_sha1(passphrase, strlen(passphrase),
+ ret = archive_pbkdf2_sha1(passphrase, strlen(passphrase),
salt, salt_len, 1000, derived_key, key_len * 2 + 2);
+ if (ret != 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ ret == CRYPTOR_STUB_FUNCTION ? "Encryption is unsupported due to "
+ "lack of crypto library" : "Failed to process passphrase");
+ return (ARCHIVE_FAILED);
+ }
ret = archive_encrypto_aes_ctr_init(&zip->cctx, derived_key, key_len);
if (ret != 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Decryption is unsupported due to lack of crypto library");
+ "Failed to initialize AES CTR mode");
return (ARCHIVE_FAILED);
}
ret = archive_hmac_sha1_init(&zip->hctx, derived_key + key_len,
static const char koi8_string[] = "\xD0\xD2\xC9";
static const wchar_t wcs_string[] = L"\U0000043f\U00000440\U00000438";
struct archive_mstring mstr;
+ struct archive *a;
int r;
memset(&mstr, 0, sizeof(mstr));
skipping("KOI8-R locale not available on this system.");
return;
}
+ a = archive_write_new();
+ assertEqualInt(ARCHIVE_OK, archive_write_set_format_pax(a));
+ if (archive_write_set_options(a, "hdrcharset=UTF-8") != ARCHIVE_OK) {
+ skipping("This system cannot convert character-set"
+ " from KOI8-R to UTF-8.");
+ archive_write_free(a);
+ return;
+ }
+ archive_write_free(a);
r = archive_mstring_update_utf8(NULL, &mstr, utf8_string);
const char *name = "test_read_filter_gzip_recursive.gz";
struct archive *a;
- if (!canGzip()) {
- skipping("gzip not available");
+ if (archive_zlib_version() == NULL) {
+ skipping("zlib not available");
return;
}
const char test_txt[] = "123";
int size = sizeof(test_txt) - 1;
- extract_reference_file(reffile);
assert((a = archive_read_new()) != NULL);
- assertA(0 == archive_read_support_filter_all(a));
- assertA(0 == archive_read_support_format_all(a));
- assertA(0 == archive_read_open_filename(a, reffile, bs));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.txt.txt", archive_entry_pathname(ae));
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping(
+ "7zip:lzma decoding is not supported on this platform");
+ } else {
+ extract_reference_file(reffile);
+ assertA(0 == archive_read_support_filter_all(a));
+ assertA(0 == archive_read_support_format_all(a));
+ assertA(0 == archive_read_open_filename(a, reffile, bs));
- assertA(size == archive_read_data(a, buff, size));
- assertEqualMem(buff, test_txt, size);
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.txt.txt", archive_entry_pathname(ae));
+
+ assertA(size == archive_read_data(a, buff, size));
+ assertEqualMem(buff, test_txt, size);
+
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
const char test_txt[] = "123";
int size = sizeof(test_txt) - 1;
- extract_reference_file(reffile);
assert((a = archive_read_new()) != NULL);
- assertA(0 == archive_read_support_filter_all(a));
- assertA(0 == archive_read_support_format_all(a));
- assertA(0 == archive_read_open_filename(a, reffile, bs));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.txt.txt", archive_entry_pathname(ae));
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping(
+ "7zip:lzma decoding is not supported on this platform");
+ } else {
+ extract_reference_file(reffile);
+ assertA(0 == archive_read_support_filter_all(a));
+ assertA(0 == archive_read_support_format_all(a));
+ assertA(0 == archive_read_open_filename(a, reffile, bs));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.txt.txt", archive_entry_pathname(ae));
+
+ assertA(size == archive_read_data(a, buff, size));
+ assertEqualMem(buff, test_txt, size);
- assertA(size == archive_read_data(a, buff, size));
- assertEqualMem(buff, test_txt, size);
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ }
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
const char test_txt[] = "123";
int size = sizeof(test_txt) - 1;
- extract_reference_file(reffile);
assert((a = archive_read_new()) != NULL);
- assertA(0 == archive_read_support_filter_all(a));
- assertA(0 == archive_read_support_format_all(a));
- assertA(0 == archive_read_open_filename(a, reffile, bs));
- assertA(0 == archive_read_next_header(a, &ae));
- assertEqualString("test.txt.txt", archive_entry_pathname(ae));
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
+ skipping(
+ "7zip:lzma decoding is not supported on this platform");
+ } else {
+ extract_reference_file(reffile);
+ assertA(0 == archive_read_support_filter_all(a));
+ assertA(0 == archive_read_support_format_all(a));
+ assertA(0 == archive_read_open_filename(a, reffile, bs));
+
+ assertA(0 == archive_read_next_header(a, &ae));
+ assertEqualString("test.txt.txt", archive_entry_pathname(ae));
- assertA(size == archive_read_data(a, buff, size));
- assertEqualMem(buff, test_txt, size);
+ assertA(size == archive_read_data(a, buff, size));
+ assertEqualMem(buff, test_txt, size);
- assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
- assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+ }
+
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
}
DEFINE_TEST(test_read_format_7zip_extract_second)
assert((a = archive_read_new()) != NULL);
- if (ARCHIVE_OK != archive_read_support_filter_gzip(a)) {
+ if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
skipping(
- "7zip:deflate decoding is not supported on this platform");
+ "7zip:lzma decoding is not supported on this platform");
} else {
test_powerpc_filter("test_read_format_7zip_lzma2_powerpc.7z");
}
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
return;
}
- assertEqualIntA(a, ARCHIVE_OK, r);
+ if (r == ARCHIVE_WARN && canGzip())
+ assertEqualString(archive_error_string(a), "Using external gzip program");
+ else
+ assertEqualIntA(a, ARCHIVE_OK, r);
assertEqualInt(ARCHIVE_OK,
archive_read_open_memory(a, archive, sizeof(archive)));
assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualInt(rbuff[0], 0x1f);
assertEqualInt(rbuff[1], 0x8b);
assertEqualInt(rbuff[2], 0x08);
- assertEqualInt(rbuff[3], 0x08);
- assertEqualInt(rbuff[8], 2); /* RFC 1952 flag for compression level 9 */
- assertEqualString((const char*)rbuff+10, "testorgfilename");
+ /* RFC 1952 flag for compression level 9 */
+ assertEqualInt(rbuff[8], 2);
+ /* External gzip program might not save filename */
+ if (!use_prog || rbuff[3] == 0x08) {
+ assertEqualInt(rbuff[3], 0x08);
+ assertEqualString((const char*)rbuff+10, "testorgfilename");
+ } else {
+ assertEqualInt(rbuff[3], 0x00);
+ }
/* Curiously, this test fails; the test data above compresses
* better at default compression than at level 9. */
archive_entry_free(ae);
assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- failure("Timestamp should be recorded");
- assert(memcmp(buff + 4, "\x00\x00\x00\x00", 4) != 0);
+ /* External gzip program might not save timestamp */
+ if (!use_prog) {
+ failure("Timestamp should be recorded");
+ assert(memcmp(buff + 4, "\x00\x00\x00\x00", 4) != 0);
+ }
/* Test2: set "gzip:!timestamp" option. */
assert((a = archive_write_new()) != NULL);
/* Test C arg - match case-insensitive */
DEFINE_TEST(test_C)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertEmptyFile("test.err");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test L arg - make names lowercase */
DEFINE_TEST(test_L)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/caps");
+#else
+ skipping("zlib not available");
+#endif
}
extract_reference_file(reffile);
r = systemf("%s -P password %s >test.out 2>test.err", testprog, reffile);
- assertEqualInt(0, r);
- assertNonEmptyFile("test.out");
- assertEmptyFile("test.err");
+ if (r == 256) {
+ assertTextFileContents("unzip: Decryption is unsupported due to lack of crypto library\n", "test.err");
+ } else {
+ assertEqualInt(0, r);
+ assertNonEmptyFile("test.out");
+ assertEmptyFile("test.err");
- assertTextFileContents("plaintext\n", "encrypted/file.txt");
+ assertTextFileContents("plaintext\n", "encrypted/file.txt");
+ }
}
/* This test just does a basic zip decompression */
DEFINE_TEST(test_basic)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test d arg - extract to target dir - before zipfile argument */
DEFINE_TEST(test_d_before_zipfile)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "foobar/test_basic/b");
assertTextFileContents("contents c\n", "foobar/test_basic/c");
assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test d arg - extract to target dir - after zipfile argument */
DEFINE_TEST(test_d_after_zipfile)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "foobar/test_basic/b");
assertTextFileContents("contents c\n", "foobar/test_basic/c");
assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test double dash arg - swallow "--" and use next argument as file name */
DEFINE_TEST(test_doubledash)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test that the glob works */
DEFINE_TEST(test_glob)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertFileNotExists("test_basic/c");
assertFileNotExists("test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test j arg - don't make directories */
DEFINE_TEST(test_j)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "b");
assertTextFileContents("contents c\n", "c");
assertTextFileContents("contents CAPS\n", "CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test n arg - don't overwrite existing files */
DEFINE_TEST(test_n)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("orig b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test o arg - overwrite existing files */
DEFINE_TEST(test_o)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test p arg - Print to stdout */
DEFINE_TEST(test_p)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertEqualInt(0, r);
assertTextFileContents("contents a\ncontents b\ncontents c\ncontents CAPS\n", "test.out");
assertEmptyFile("test.err");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test q arg - Quiet */
DEFINE_TEST(test_q)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertTextFileContents("contents c\n", "test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Ensure single-file zips work */
DEFINE_TEST(test_singlefile)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_singlefile.zip";
int r;
assertEmptyFile("test.err");
assertTextFileContents("hello\n", "file.txt");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test t arg - Test zip contents */
DEFINE_TEST(test_t)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertEqualInt(0, r);
assertNonEmptyFile("test.out");
assertEmptyFile("test.err");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test x arg with single exclude path */
DEFINE_TEST(test_x_single)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertTextFileContents("contents b\n", "test_basic/b");
assertFileNotExists("test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test x arg with multiple exclude paths */
DEFINE_TEST(test_x_multiple)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertFileNotExists("test_basic/b");
assertFileNotExists("test_basic/c");
assertTextFileContents("contents CAPS\n", "test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}
/* Test x arg with multiple exclude paths and a d arg afterwards */
DEFINE_TEST(test_x_multiple_with_d)
{
+#ifdef HAVE_LIBZ
const char *reffile = "test_basic.zip";
int r;
assertFileNotExists("foobar/test_basic/b");
assertFileNotExists("foobar/test_basic/c");
assertTextFileContents("contents CAPS\n", "foobar/test_basic/CAPS");
+#else
+ skipping("zlib not available");
+#endif
}