mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 12:34:47 +00:00
Adopt util::GenerateUuid()
This commit is contained in:
parent
d2ad83dbb4
commit
7d9015de1e
4 changed files with 17 additions and 15 deletions
|
@ -82,10 +82,9 @@ namespace ams::ncm {
|
|||
|
||||
Result ContentStorageInterface::GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) {
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
ams::os::GenerateRandomBytes(out.GetPointer(), sizeof(PlaceHolderId));
|
||||
char placeholder_str[FS_MAX_PATH] = {0};
|
||||
GetStringFromPlaceHolderId(placeholder_str, *out.GetPointer());
|
||||
PlaceHolderId placeholder_id;
|
||||
placeholder_id.uuid = util::GenerateUuid();
|
||||
out.SetValue(placeholder_id);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
@ -121,7 +120,7 @@ namespace ams::ncm {
|
|||
|
||||
Result ContentStorageInterface::WritePlaceHolder(PlaceHolderId placeholder_id, u64 offset, sf::InBuffer data) {
|
||||
/* Offset is too large */
|
||||
R_UNLESS(offset<= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_UNLESS(offset <= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_TRY(this->EnsureEnabled());
|
||||
R_TRY(this->placeholder_accessor.Write(placeholder_id, offset, data.GetPointer(), data.GetSize()));
|
||||
return ResultSuccess();
|
||||
|
@ -363,7 +362,7 @@ namespace ams::ncm {
|
|||
|
||||
Result ContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) {
|
||||
/* Offset is too large */
|
||||
R_UNLESS(offset<= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_UNLESS(offset <= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_TRY(this->EnsureEnabled());
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
this->GetContentPath(content_path, content_id);
|
||||
|
@ -450,7 +449,7 @@ namespace ams::ncm {
|
|||
|
||||
Result ContentStorageInterface::WriteContentForDebug(ContentId content_id, u64 offset, sf::InBuffer data) {
|
||||
/* Offset is too large */
|
||||
R_UNLESS(offset<= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_UNLESS(offset <= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
bool is_development = false;
|
||||
|
|
|
@ -23,13 +23,13 @@ namespace ams::ncm::path {
|
|||
|
||||
u16 Get16BitSha256HashPrefix(util::Uuid uuid) {
|
||||
u8 hash[SHA256_HASH_SIZE];
|
||||
sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid));
|
||||
sha256CalculateHash(hash, uuid.data, sizeof(util::Uuid));
|
||||
return static_cast<u16>(hash[0]) | (static_cast<u16>(hash[1]) << 8);
|
||||
}
|
||||
|
||||
u8 Get8BitSha256HashPrefix(util::Uuid uuid) {
|
||||
u8 hash[SHA256_HASH_SIZE];
|
||||
sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid));
|
||||
sha256CalculateHash(hash, uuid.data, sizeof(util::Uuid));
|
||||
return hash[0];
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ namespace ams::ncm {
|
|||
|
||||
Result ReadOnlyContentStorageInterface::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, u64 offset) {
|
||||
/* Offset is too large */
|
||||
R_UNLESS(offset<= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_UNLESS(offset <= std::numeric_limits<s64>::max(), ncm::ResultInvalidOffset());
|
||||
R_TRY(this->EnsureEnabled());
|
||||
|
||||
char content_path[FS_MAX_PATH] = {0};
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace ams::ncm {
|
|||
R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderDirectoryEntry());
|
||||
R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, ncm::ResultInvalidPlaceHolderDirectoryEntry());
|
||||
|
||||
PlaceHolderId placeholder_id = {0};
|
||||
u8 tmp[sizeof(PlaceHolderId)] = {};
|
||||
char byte_string[2];
|
||||
char* end_ptr;
|
||||
u64 converted_val;
|
||||
|
@ -46,20 +46,21 @@ namespace ams::ncm {
|
|||
byte_string[1] = name_char_pair[1];
|
||||
|
||||
converted_val = strtoull(byte_string, &end_ptr, 0x10);
|
||||
placeholder_id.uuid[i] = (u8)converted_val;
|
||||
tmp[i] = (u8)converted_val;
|
||||
}
|
||||
|
||||
PlaceHolderId placeholder_id;
|
||||
std::memcpy(placeholder_id.uuid.data, tmp, sizeof(PlaceHolderId));
|
||||
*out = placeholder_id;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
std::optional<ContentId> GetContentIdFromString(const char* str, size_t len) {
|
||||
ContentId content_id = {0};
|
||||
|
||||
if (len < 0x20) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
u8 tmp[sizeof(ContentId)] = {};
|
||||
char byte_string[2];
|
||||
char* end_ptr;
|
||||
u64 converted_val;
|
||||
|
@ -71,9 +72,11 @@ namespace ams::ncm {
|
|||
byte_string[1] = char_par[1];
|
||||
|
||||
converted_val = strtoull(byte_string, &end_ptr, 0x10);
|
||||
content_id.uuid[i] = (u8)converted_val;
|
||||
tmp[i] = (u8)converted_val;
|
||||
}
|
||||
|
||||
ContentId content_id;
|
||||
std::memcpy(content_id.uuid.data, tmp, sizeof(ContentId));
|
||||
return std::optional<ContentId>(content_id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue