1 /*
2  * Copyright (c) 2022 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 REMOTE_MSG_UTIL_H
17 #define REMOTE_MSG_UTIL_H
18 
19 #include "attributes.h"
20 #include "co_auth_client_defines.h"
21 #include "iam_logger.h"
22 #include "user_auth_common_defines.h"
23 #include "remote_message.h"
24 
25 #define LOG_TAG "USER_AUTH_SA"
26 
27 namespace OHOS {
28 namespace UserIam {
29 namespace UserAuth {
30 class RemoteMsgUtil {
31 public:
32     static bool GetConnectionName(uint64_t contextId, std::string &connectionName);
33 
34     // QUERY_EXECUTOR_INFO
35     static bool GetQueryExecutorInfoReply(const std::vector<int32_t> authTypes, int32_t executorRole,
36         std::string remoteUdid, Attributes &attr);
37     static bool DecodeQueryExecutorInfoReply(const Attributes &attr, std::vector<ExecutorInfo> &executorInfoArray);
38 
39     static bool EncodeAuthParam(const AuthParamInner &authParam, Attributes &attr);
40     static bool DecodeAuthParam(const Attributes &attr, AuthParamInner &authParam);
41 
42 private:
43     // QUERY_EXECUTOR_INFO
44     static bool EncodeQueryExecutorInfoReply(const std::vector<ExecutorInfo> &executorInfoArray,
45         const std::vector<uint8_t> &signedRemoteExecutorInfo, Attributes &attr);
46     static bool SetExecutorInfoToAttributes(const ExecutorInfo &executorInfo, Attributes &attr);
47     static bool GetExecutorInfoFromAttributes(const Attributes &Attr, std::vector<uint8_t> &signedRemoteExecutorInfo,
48         ExecutorInfo &executorInfo);
49     static bool SetExecutorInfoArrayToAttributes(const std::vector<ExecutorInfo> &executorInfoArray, Attributes &attr);
50     static bool GetExecutorInfoArrayFromAttributes(const Attributes &Attr,
51         std::vector<uint8_t> &signedRemoteExecutorInfo, std::vector<ExecutorInfo> &executorInfoArray);
52 };
53 } // namespace UserAuth
54 } // namespace UserIam
55 } // namespace OHOS
56 #endif // REMOTE_MSG_UTIL_H