1 /*
2  * Copyright (c) 2024 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 #include "tls_utils_test.h"
17 
18 namespace OHOS {
19 namespace NetStack {
20 namespace TlsSocket {
ChangeToFile(const std::string_view fileName)21 std::string TlsUtilsTest::ChangeToFile(const std::string_view fileName)
22 {
23     std::ifstream file;
24     file.open(fileName);
25     std::stringstream ss;
26     ss << file.rdbuf();
27     std::string infos = ss.str();
28     file.close();
29     return infos;
30 }
31 
GetIp(std::string ip)32 std::string TlsUtilsTest::GetIp(std::string ip)
33 {
34     return ip.substr(0, ip.length() - 1);
35 }
36 
CheckCaFileExistence(const char * function)37 bool TlsUtilsTest::CheckCaFileExistence(const char *function)
38 {
39     if (access(CA_DER.data(), 0)) {
40         std::cout << "CA file does not exist! (" << function << ")";
41         return false;
42     }
43     return true;
44 }
45 
CheckCaPathChainExistence(const char * function)46 bool TlsUtilsTest::CheckCaPathChainExistence(const char *function)
47 {
48     if (access(CA_PATH_CHAIN.data(), 0)) {
49         std::cout << "CA file does not exist! (" << function << ")";
50         return false;
51     }
52     return true;
53 }
54 } // namespace TlsSocket
55 } // namespace NetStack
56 } // namespace OHOS
57