1 /* 2 * Copyright (c) 2025 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 NET_WEBSOCKET_UTILS_H 17 #define NET_WEBSOCKET_UTILS_H 18 19 #include <cstddef> 20 #include <cstring> 21 #include <iostream> 22 #include <memory> 23 #include <string> 24 #include <chrono> 25 #include <map> 26 27 #include "constant.h" 28 #include "cj_ffi/cj_common_ffi.h" 29 30 namespace OHOS::NetStack::NetWebSocket { 31 uint8_t* MallocUInt8(const std::string& origin); 32 char* MallocCString(const std::string& origin); 33 CArrString Map2CArrString(std::map<std::string, std::string> map); 34 void FreeCArrString(CArrString& arrStr); 35 36 class SecureChar { 37 public: 38 SecureChar(); 39 ~SecureChar(); 40 explicit SecureChar(const std::string &secureChar); 41 SecureChar(const uint8_t *secureChar, size_t length); 42 SecureChar(const SecureChar &secureChar); 43 SecureChar &operator=(const SecureChar &secureChar); 44 45 const char *Data() const; 46 size_t Length() const; 47 48 private: 49 size_t length_ = 0; 50 std::unique_ptr<char[]> data_ = nullptr; 51 }; 52 } 53 #endif 54 55