Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cdoc/Tar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ libcdoc::TarConsumer::open(const std::string& name, int64_t size)
} else {
path = std::filesystem::path("./PaxHeaders.X") / path.filename();
}
LOG_DBG("Pax path: {}", path.string());
if (auto rv = writeHeader(path.string(), paxData.size(), 'x'); rv != OK)
std::string paxPath = decodeName(path);
LOG_DBG("Pax path: {}", paxPath);
if (auto rv = writeHeader(paxPath, paxData.size(), 'x'); rv != OK)
return rv;
if (auto rv = _dst->write((const uint8_t *) paxData.data(), paxData.size()); rv != paxData.size())
return rv < OK ? rv : OUTPUT_ERROR;
Expand Down
6 changes: 6 additions & 0 deletions cdoc/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ static auto encodeName(std::string_view path)
return std::u8string_view(reinterpret_cast<const char8_t*>(path.data()), path.size());
}

static std::string decodeName(const std::filesystem::path& path)
{
auto name = path.u8string();
return {reinterpret_cast<const char*>(name.data()), name.size()};
}

std::string toBase64(const uint8_t *data, size_t len);

static std::string toBase64(const std::vector<uint8_t> &data) {
Expand Down
18 changes: 6 additions & 12 deletions test/libcdoc_boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ const map<string, string> ExpectedParsedLabel {
{"cn", "JÕEORG,JAAK-KRISTJAN,38001085718"}
};

static string decodeName(fs::path path)
{
auto name = path.u8string();
return {reinterpret_cast<const char*>(name.data()), name.size()};
}

/**
* @brief The base class for Test Fixtures.
*/
Expand Down Expand Up @@ -557,7 +551,7 @@ BOOST_FIXTURE_TEST_CASE_WITH_DECOR(DecryptWithPasswordAndLabel, DecryptFixture,
* utf::description("Decrypting a file with password and given label"))
{
libcdoc::RcptInfo rcpt {.type=libcdoc::RcptInfo::LOCK, .label=Label, .secret=Password};
decrypt({checkDataFile(sources[0])}, checkTargetFile("PasswordUsageWithoutLabel.cdoc"), decodeName(tmpDataPath), rcpt);
decrypt({checkDataFile(sources[0])}, checkTargetFile("PasswordUsageWithoutLabel.cdoc"), libcdoc::decodeName(tmpDataPath), rcpt);
}
BOOST_AUTO_TEST_SUITE_END()

Expand Down Expand Up @@ -828,16 +822,16 @@ struct PaxFixture : public FixtureBase
std::vector<libcdoc::RcptInfo> rcpts {
{libcdoc::RcptInfo::PASSWORD, "label", {}, Password}
};
encrypt(2, {srcFile.string()}, cdocFile.string(), rcpts);
encrypt(2, {libcdoc::decodeName(srcFile)}, libcdoc::decodeName(cdocFile), rcpts);

libcdoc::RcptInfo rcpt {
.type=libcdoc::RcptInfo::LOCK,
.label="label",
.secret=Password
};
libcdoc::ToolConf conf;
conf.input_files.push_back(cdocFile.string());
conf.out = outDir.string();
conf.input_files.push_back(libcdoc::decodeName(cdocFile));
conf.out = libcdoc::decodeName(outDir);
libcdoc::CDocCipher cipher;
BOOST_CHECK_EQUAL(cipher.Decrypt(conf, rcpt), 0);
}
Expand All @@ -860,8 +854,8 @@ BOOST_FIXTURE_TEST_CASE(LongFilename, PaxFixture)

BOOST_FIXTURE_TEST_CASE(NonAsciiFilename, PaxFixture)
{
// õäöü in UTF-8
const fs::path namePath(u8"\u00f5\u00e4\u00f6\u00fc.txt");
// Include characters outside Windows-1252 to catch accidental ACP conversions.
const fs::path namePath(u8"\u00f5\u00e4\u00f6\u00fc-\u03b4-\u0436.txt");
const fs::path src = tmpDataPath / namePath;
std::ofstream(src) << "hello";
BOOST_TEST_REQUIRE(fs::exists(src));
Expand Down
Loading