From e6e0ce5902b91844555a46304ec718295bfeb26a Mon Sep 17 00:00:00 2001 From: zpf Date: Thu, 4 Sep 2025 09:56:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AA=92=E4=BD=93=E6=95=B0=E5=AD=97=E7=89=88?= =?UTF-8?q?=E6=9D=83=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zpf --- .../c/drm_capi/native_mediakeysystem.cpp | 4 +++ .../unittest/src/drm_framework_unittest.cpp | 29 ++++++++++++++++ services/utils/include/drm_common_utils.h | 34 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 services/utils/include/drm_common_utils.h diff --git a/frameworks/c/drm_capi/native_mediakeysystem.cpp b/frameworks/c/drm_capi/native_mediakeysystem.cpp index 347a74b..0db3b20 100644 --- a/frameworks/c/drm_capi/native_mediakeysystem.cpp +++ b/frameworks/c/drm_capi/native_mediakeysystem.cpp @@ -28,6 +28,7 @@ #include "drm_api_operation.h" #include "media_key_system_factory_impl.h" #include "drm_error_code.h" +#include "drm_common_utils.h" using namespace OHOS::DrmStandard; @@ -98,6 +99,9 @@ Drm_ErrCode OH_MediaKeySystem_GetMediaKeySystems(DRM_MediaKeySystemDescription * DRM_CHECK_AND_RETURN_RET_LOG((ret == DRM_ERR_OK), DRM_ERR_UNKNOWN, "GetMediaKeySystems call Failed!"); for (auto it = keySystemNames.begin(); it != keySystemNames.end(); it++) { + if (!IsUuidValid(it->second)) { + continue; + } if (it->first.size() != 0) { ret = strcpy_s(description[times].name, sizeof(description[times].name) - 1, it->first.c_str()); if (ret != 0) { diff --git a/frameworks/native/test/unittest/src/drm_framework_unittest.cpp b/frameworks/native/test/unittest/src/drm_framework_unittest.cpp index cf02385..6f2af67 100644 --- a/frameworks/native/test/unittest/src/drm_framework_unittest.cpp +++ b/frameworks/native/test/unittest/src/drm_framework_unittest.cpp @@ -47,6 +47,7 @@ #include "imedia_key_session_service.h" #include "imedia_key_session_service_callback.h" #include "media_key_session_service_callback_stub.h" +#include "drm_common_utils.h" #define DRM_SAMPLE_CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ do { \ @@ -3946,5 +3947,33 @@ HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_CreateMediaKeySession_MAX_01, TestSi EXPECT_EQ(errNo, DRM_ERR_OK); } +HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_IsUuidValid_01, TestSize.Level0) +{ + EXPECT_TRUE(IsUuidValid("0123456789ABCDEF")); + EXPECT_TRUE(IsUuidValid("abcdef1234567890")); + EXPECT_TRUE(IsUuidValid("a1b2c3d4e5f6")); +} + +HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_IsUuidValid_02, TestSize.Level0) +{ + EXPECT_FALSE(IsUuidValid("")); +} + +HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_IsUuidValid_03, TestSize.Level0) +{ + EXPECT_FALSE(IsUuidValid("123G456")); + EXPECT_FALSE(IsUuidValid("xyz123")); + EXPECT_FALSE(IsUuidValid("123456_")); + EXPECT_FALSE(IsUuidValid(" 123456")); +} + +HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_IsUuidValid_04, TestSize.Level0) +{ + EXPECT_TRUE(IsUuidValid("0")); + EXPECT_TRUE(IsUuidValid("f")); + EXPECT_TRUE(IsUuidValid("F")); + EXPECT_TRUE(IsUuidValid("09AFaf")); + EXPECT_FALSE(IsUuidValid("09AG")); +} } // DrmStandard } // OHOS diff --git a/services/utils/include/drm_common_utils.h b/services/utils/include/drm_common_utils.h new file mode 100644 index 0000000..3624031 --- /dev/null +++ b/services/utils/include/drm_common_utils.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DRM_COMMON_UTILS_H +#define DRM_COMMON_UTILS_H +#include +#include +#include "drm_log.h" + +namespace OHOS { +namespace DrmStandard { +bool IsUuidValid(const std::string &uuid) +{ + DRM_CHECK_AND_RETURN_RET_LOG(!uuid.empty(), false, "uuid is empty"); + for (uint32_t i = 0; i < uuid.size(); i++) { + DRM_CHECK_AND_RETURN_RET_LOG(isxdigit(uuid[i]), false, "uuid is invalid"); + } + return true; +} +} // namespace DrmStandard +} // namespace OHOS + +#endif \ No newline at end of file -- Gitee