summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/bcat/bcat_util.h
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2024-02-10 22:00:43 +0100
committerGitHub <noreply@github.com>2024-02-10 22:00:43 +0100
commit2337397a1530e2d0cd6cab4bd22517747b80de6c (patch)
tree8bcabd801561c8e63097fff8861f22a09fe8a9d6 /src/core/hle/service/bcat/bcat_util.h
parentMerge pull request #12949 from liamwhite/multi-wait (diff)
parentservice: bcat: Address review issues (diff)
downloadyuzu-2337397a1530e2d0cd6cab4bd22517747b80de6c.tar
yuzu-2337397a1530e2d0cd6cab4bd22517747b80de6c.tar.gz
yuzu-2337397a1530e2d0cd6cab4bd22517747b80de6c.tar.bz2
yuzu-2337397a1530e2d0cd6cab4bd22517747b80de6c.tar.lz
yuzu-2337397a1530e2d0cd6cab4bd22517747b80de6c.tar.xz
yuzu-2337397a1530e2d0cd6cab4bd22517747b80de6c.tar.zst
yuzu-2337397a1530e2d0cd6cab4bd22517747b80de6c.zip
Diffstat (limited to 'src/core/hle/service/bcat/bcat_util.h')
-rw-r--r--src/core/hle/service/bcat/bcat_util.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/core/hle/service/bcat/bcat_util.h b/src/core/hle/service/bcat/bcat_util.h
new file mode 100644
index 000000000..6bf2657ee
--- /dev/null
+++ b/src/core/hle/service/bcat/bcat_util.h
@@ -0,0 +1,39 @@
+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include <array>
+#include <cctype>
+#include <mbedtls/md5.h>
+
+#include "core/hle/service/bcat/bcat_result.h"
+#include "core/hle/service/bcat/bcat_types.h"
+
+namespace Service::BCAT {
+
+// For a name to be valid it must be non-empty, must have a null terminating character as the final
+// char, can only contain numbers, letters, underscores and a hyphen if directory and a period if
+// file.
+constexpr Result VerifyNameValidInternal(std::array<char, 0x20> name, char match_char) {
+ const auto null_chars = std::count(name.begin(), name.end(), 0);
+ const auto bad_chars = std::count_if(name.begin(), name.end(), [match_char](char c) {
+ return !std::isalnum(static_cast<u8>(c)) && c != '_' && c != match_char && c != '\0';
+ });
+ if (null_chars == 0x20 || null_chars == 0 || bad_chars != 0 || name[0x1F] != '\0') {
+ LOG_ERROR(Service_BCAT, "Name passed was invalid!");
+ return ResultInvalidArgument;
+ }
+
+ return ResultSuccess;
+}
+
+constexpr Result VerifyNameValidDir(DirectoryName name) {
+ return VerifyNameValidInternal(name, '-');
+}
+
+constexpr Result VerifyNameValidFile(FileName name) {
+ return VerifyNameValidInternal(name, '.');
+}
+
+} // namespace Service::BCAT