Remove usage of PathUtil from KeyBag.cpp

This commit is contained in:
jakcron 2022-03-26 18:19:16 +08:00
parent 6b2919ced1
commit aea73605d4

View file

@ -452,17 +452,13 @@ void nstool::KeyBagInitializer::importTitleKeyFile(const tc::io::Path& keyfile_p
void nstool::KeyBagInitializer::importCertificateChain(const tc::io::Path& cert_path) void nstool::KeyBagInitializer::importCertificateChain(const tc::io::Path& cert_path)
{ {
// save file path string for error messages
std::string cert_path_str;
tc::io::PathUtil::pathToUnixUTF8(cert_path, cert_path_str);
// open cert file // open cert file
std::shared_ptr<tc::io::FileStream> certfile_stream; std::shared_ptr<tc::io::FileStream> certfile_stream;
try { try {
certfile_stream = std::make_shared<tc::io::FileStream>(tc::io::FileStream(cert_path, tc::io::FileMode::Open, tc::io::FileAccess::Read)); certfile_stream = std::make_shared<tc::io::FileStream>(tc::io::FileStream(cert_path, tc::io::FileMode::Open, tc::io::FileAccess::Read));
} }
catch (tc::io::FileNotFoundException& e) { catch (tc::io::FileNotFoundException& e) {
fmt::print("[WARNING] Failed to open certificate file \"{:s}\" ({:s}).\n", cert_path_str, e.error()); fmt::print("[WARNING] Failed to open certificate file \"{:s}\" ({:s}).\n", cert_path.to_string(), e.error());
return; return;
} }
@ -470,7 +466,7 @@ void nstool::KeyBagInitializer::importCertificateChain(const tc::io::Path& cert_
size_t cert_raw_size = tc::io::IOUtil::castInt64ToSize(certfile_stream->length()); size_t cert_raw_size = tc::io::IOUtil::castInt64ToSize(certfile_stream->length());
if (cert_raw_size > 0x10000) if (cert_raw_size > 0x10000)
{ {
fmt::print("[WARNING] Certificate file \"{:s}\" was too large.\n", cert_path_str); fmt::print("[WARNING] Certificate file \"{:s}\" was too large.\n", cert_path.to_string());
return; return;
} }
@ -504,24 +500,20 @@ void nstool::KeyBagInitializer::importCertificateChain(const tc::io::Path& cert_
} }
} }
catch (tc::Exception& e) { catch (tc::Exception& e) {
fmt::print("[WARNING] Certificate file \"{:s}\" is corrupted ({:s}).\n", cert_path_str, e.error()); fmt::print("[WARNING] Certificate file \"{:s}\" is corrupted ({:s}).\n", cert_path.to_string(), e.error());
return; return;
} }
} }
void nstool::KeyBagInitializer::importTicket(const tc::io::Path& tik_path) void nstool::KeyBagInitializer::importTicket(const tc::io::Path& tik_path)
{ {
// save file path string for error messages // open tik file
std::string tik_path_str;
tc::io::PathUtil::pathToUnixUTF8(tik_path, tik_path_str);
// open cert file
std::shared_ptr<tc::io::FileStream> tik_stream; std::shared_ptr<tc::io::FileStream> tik_stream;
try { try {
tik_stream = std::make_shared<tc::io::FileStream>(tc::io::FileStream(tik_path, tc::io::FileMode::Open, tc::io::FileAccess::Read)); tik_stream = std::make_shared<tc::io::FileStream>(tc::io::FileStream(tik_path, tc::io::FileMode::Open, tc::io::FileAccess::Read));
} }
catch (tc::io::FileNotFoundException& e) { catch (tc::io::FileNotFoundException& e) {
fmt::print("[WARNING] Failed to open ticket \"{:s}\" ({:s}).\n", tik_path_str, e.error()); fmt::print("[WARNING] Failed to open ticket \"{:s}\" ({:s}).\n", tik_path.to_string(), e.error());
return; return;
} }
@ -529,11 +521,11 @@ void nstool::KeyBagInitializer::importTicket(const tc::io::Path& tik_path)
size_t tik_raw_size = tc::io::IOUtil::castInt64ToSize(tik_stream->length()); size_t tik_raw_size = tc::io::IOUtil::castInt64ToSize(tik_stream->length());
if (tik_raw_size > 0x10000) if (tik_raw_size > 0x10000)
{ {
fmt::print("[WARNING] Ticket \"{:s}\" was too large.\n", tik_path_str); fmt::print("[WARNING] Ticket \"{:s}\" was too large.\n", tik_path.to_string());
return; return;
} }
// import cert data // import tik data
tc::ByteData tik_raw = tc::ByteData(tik_raw_size); tc::ByteData tik_raw = tc::ByteData(tik_raw_size);
tik_stream->seek(0, tc::io::SeekOrigin::Begin); tik_stream->seek(0, tc::io::SeekOrigin::Begin);
tik_stream->read(tik_raw.data(), tik_raw.size()); tik_stream->read(tik_raw.data(), tik_raw.size());
@ -594,7 +586,7 @@ void nstool::KeyBagInitializer::importTicket(const tc::io::Path& tik_path)
} }
catch (tc::Exception& e) { catch (tc::Exception& e) {
fmt::print("[WARNING] Ticket \"{:s}\" is corrupted ({:s}).\n", tik_path_str, e.error()); fmt::print("[WARNING] Ticket \"{:s}\" is corrupted ({:s}).\n", tik_path.to_string(), e.error());
return; return;
} }
} }