mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-07-14 21:12:13 +02:00
Adopt util::GenerateUuid()
This commit is contained in:
parent
d2ad83dbb4
commit
7d9015de1e
@ -82,10 +82,9 @@ namespace ams::ncm {
|
|||||||
|
|
||||||
Result ContentStorageInterface::GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) {
|
Result ContentStorageInterface::GeneratePlaceHolderId(sf::Out<PlaceHolderId> out) {
|
||||||
R_TRY(this->EnsureEnabled());
|
R_TRY(this->EnsureEnabled());
|
||||||
|
PlaceHolderId placeholder_id;
|
||||||
ams::os::GenerateRandomBytes(out.GetPointer(), sizeof(PlaceHolderId));
|
placeholder_id.uuid = util::GenerateUuid();
|
||||||
char placeholder_str[FS_MAX_PATH] = {0};
|
out.SetValue(placeholder_id);
|
||||||
GetStringFromPlaceHolderId(placeholder_str, *out.GetPointer());
|
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ namespace ams::ncm::path {
|
|||||||
|
|
||||||
u16 Get16BitSha256HashPrefix(util::Uuid uuid) {
|
u16 Get16BitSha256HashPrefix(util::Uuid uuid) {
|
||||||
u8 hash[SHA256_HASH_SIZE];
|
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);
|
return static_cast<u16>(hash[0]) | (static_cast<u16>(hash[1]) << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 Get8BitSha256HashPrefix(util::Uuid uuid) {
|
u8 Get8BitSha256HashPrefix(util::Uuid uuid) {
|
||||||
u8 hash[SHA256_HASH_SIZE];
|
u8 hash[SHA256_HASH_SIZE];
|
||||||
sha256CalculateHash(hash, uuid.uuid, sizeof(util::Uuid));
|
sha256CalculateHash(hash, uuid.data, sizeof(util::Uuid));
|
||||||
return hash[0];
|
return hash[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ namespace ams::ncm {
|
|||||||
R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderDirectoryEntry());
|
R_UNLESS(strnlen(dir_entry->d_name, 0x30) == 0x24, ncm::ResultInvalidPlaceHolderDirectoryEntry());
|
||||||
R_UNLESS(strncmp(dir_entry->d_name + 0x20, ".nca", 4) == 0, 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 byte_string[2];
|
||||||
char* end_ptr;
|
char* end_ptr;
|
||||||
u64 converted_val;
|
u64 converted_val;
|
||||||
@ -46,20 +46,21 @@ namespace ams::ncm {
|
|||||||
byte_string[1] = name_char_pair[1];
|
byte_string[1] = name_char_pair[1];
|
||||||
|
|
||||||
converted_val = strtoull(byte_string, &end_ptr, 0x10);
|
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;
|
*out = placeholder_id;
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ContentId> GetContentIdFromString(const char* str, size_t len) {
|
std::optional<ContentId> GetContentIdFromString(const char* str, size_t len) {
|
||||||
ContentId content_id = {0};
|
|
||||||
|
|
||||||
if (len < 0x20) {
|
if (len < 0x20) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u8 tmp[sizeof(ContentId)] = {};
|
||||||
char byte_string[2];
|
char byte_string[2];
|
||||||
char* end_ptr;
|
char* end_ptr;
|
||||||
u64 converted_val;
|
u64 converted_val;
|
||||||
@ -71,9 +72,11 @@ namespace ams::ncm {
|
|||||||
byte_string[1] = char_par[1];
|
byte_string[1] = char_par[1];
|
||||||
|
|
||||||
converted_val = strtoull(byte_string, &end_ptr, 0x10);
|
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);
|
return std::optional<ContentId>(content_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user