1 /* 2 * Copyright (c) 2021 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 OHOS_MSG_REQUEST_AUTH_H 17 #define OHOS_MSG_REQUEST_AUTH_H 18 19 #include <vector> 20 #include <string> 21 22 #include "nlohmann/json.hpp" 23 24 #include "msg_head.h" 25 #include "dm_app_image_info.h" 26 #include "dm_device_info.h" 27 #include "constants.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 class MsgRequestAuth { 32 public: 33 MsgRequestAuth() = default; 34 ~MsgRequestAuth() = default; MsgRequestAuth(std::string & token,std::string hostPkgName,std::string targetPkgName,const DmDeviceInfo & devReqInfo,const DmAppImageInfo & imageInfo,std::string & extras)35 MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, 36 const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, std::string &extras) : MsgRequestAuth( 37 token, hostPkgName, targetPkgName, GROUP_VISIBILITY_IS_PRIVATE, devReqInfo, imageInfo, extras) {}; 38 MsgRequestAuth(std::string &token, std::string hostPkgName, std::string targetPkgName, 39 const int32_t groupVisibility, const DmDeviceInfo &devReqInfo, const DmAppImageInfo &imageInfo, 40 std::string &extras); 41 std::vector<std::string> Encode(); 42 static std::shared_ptr<MsgRequestAuth> Decode(nlohmann::json &json, std::shared_ptr<MsgRequestAuth> msgIn); 43 static void SetThumbnailSize(nlohmann::json &json, std::shared_ptr<MsgRequestAuth> msg); 44 int32_t GetMsgSlice(); 45 int32_t GetMsgCnt(); 46 std::string GetRequestDeviceId(); 47 public: 48 std::shared_ptr<MsgHead> mHead_ {nullptr}; 49 std::string mHostPkg_; 50 std::string mTargetPkg_; 51 std::string mDeviceName_; 52 std::string mToken_; 53 std::string mDeviceId_; 54 std::string mDeviceType_; 55 std::string mAppName_; 56 std::string mAppDescription_; 57 int32_t mAuthType_ {AUTH_TYPE_PIN}; 58 int32_t mGroupVisibility_ {GROUP_VISIBILITY_IS_PRIVATE}; 59 int32_t mMsgSlice_ {0}; 60 int32_t mMsgCnt_ {0}; 61 int32_t mThumbnailSize_ {0}; 62 int32_t mAppIconSize_ {0}; 63 DmAppImageInfo mImageInfo_; 64 private: 65 std::string ToHexString(int32_t value); 66 std::string EncodeDevInfo(); 67 static void DecodeDeviceInfo(nlohmann::json &json, std::shared_ptr<MsgRequestAuth> msg); 68 int32_t GetEncodedAppInfo(const uint8_t *dataSrc, int32_t srcLen, std::string &outString); 69 void GetDecodeAppInfo(const std::string appString, uint8_t **outBuffer, int32_t &outBufferLen); 70 static bool IsMsgValid(std::shared_ptr<MsgRequestAuth> msgIn, nlohmann::json &json, std::string &deviceId, 71 int32_t index); 72 static bool IsAppInfoValid(nlohmann::json &json); 73 static void SetAuthType(nlohmann::json &json, std::shared_ptr<MsgRequestAuth> msg); 74 }; 75 } 76 } 77 78 79 #endif 80