1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CODE_SIGN_HISYSEVENT_H
17 #define CODE_SIGN_HISYSEVENT_H
18 
19 #include <hisysevent.h>
20 #include <string>
21 
22 namespace OHOS {
23 namespace Security {
24 namespace CodeSign {
ReportEnableError(std::string filePath,int32_t errCode)25 inline void ReportEnableError(std::string filePath, int32_t errCode)
26 {
27     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CODE_SIGN, "CS_ENABLE_ERR",
28         HiviewDFX::HiSysEvent::EventType::SECURITY,
29         "FILE_INFO", filePath, "ERR_TYPE", errCode);
30 }
31 
ReportLoadSAError(int32_t errCode)32 inline void ReportLoadSAError(int32_t errCode)
33 {
34     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CODE_SIGN, "CS_LOAD_SA_ERR",
35         HiviewDFX::HiSysEvent::EventType::FAULT, "ERR_TYPE", errCode);
36 }
37 
ReportInvalidCaller(const std::string & interfaceType,uint32_t tokenId)38 inline void ReportInvalidCaller(const std::string &interfaceType, uint32_t tokenId)
39 {
40     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CODE_SIGN, "CS_SA_INVALID_CALLER",
41         HiviewDFX::HiSysEvent::EventType::SECURITY,
42         "INTERFACE", interfaceType, "TOKEN_ID", tokenId);
43 }
ReportParseCodeSig(const std::string & fileInfo,int32_t errCode)44 inline void ReportParseCodeSig(const std::string &fileInfo, int32_t errCode)
45 {
46     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CODE_SIGN, "CS_PARSE_CODE_SIG",
47         HiviewDFX::HiSysEvent::EventType::FAULT,
48         "FILE_INFO", fileInfo, "ERR_TYPE", errCode);
49 }
ReportInvalidOwner(const std::string & fileInfo,const std::string & ownerID,const std::string & parsedOwnerID)50 inline void ReportInvalidOwner(const std::string &fileInfo, const std::string &ownerID,
51     const std::string &parsedOwnerID)
52 {
53     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::CODE_SIGN, "CS_INVALID_OWNER",
54         HiviewDFX::HiSysEvent::EventType::SECURITY,
55         "FILE_INFO", fileInfo, "OWNER_ID", ownerID, "PARSED_OWNER_ID", parsedOwnerID);
56 }
57 }
58 }
59 }
60 #endif