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 #ifndef ASN1_UTIL_H
17 #define ASN1_UTIL_H
18 
19 #include <cstdbool>
20 #include <cstdint>
21 #include <list>
22 #include <vector>
23 #include "telephony_log_wrapper.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 class Asn1Utils {
28 public:
29     static bool IsConstructedTag(uint32_t tag);
30     static uint32_t CalculateEncodedBytesNumForLength(uint32_t length);
31     static uint32_t ByteCountForUint(uint32_t value);
32     static void BchToString(const std::vector<uint8_t> &src, std::string &destStr);
33     static void BcdToBytes(const std::string &bcd, std::vector<uint8_t> &bytes);
34     static std::string BytesToHexStr(const std::vector<uint8_t> &bytes);
35     static std::vector<uint8_t> HexStrToBytes(const std::string &hexStr);
36     static uint32_t UintToBytes(const uint32_t value, std::vector<uint8_t> &bytes);
37     static uint32_t IntToBytes(int32_t value, std::vector<uint8_t> &dest);
38     static std::string BytesToString(const std::vector<uint8_t> &src);
39     static std::string HexStrToString(const std::string &hexStr);
40     static std::vector<uint8_t> StringToBytes(const std::string &src);
41     static int32_t BytesToInt(const std::vector<uint8_t> &src, uint32_t offset, uint32_t length);
42     static uint8_t CountTrailingZeros(const uint8_t value);
43     static uint32_t ReverseInt(uint32_t value);
44     static uint32_t ByteToHexStr(uint8_t src, std::string &dest);
45 
46 private:
47     static std::string SwapHexCharPair(const std::string &hexStr);
48     static std::string StrToHexStr(const std::string& str);
49     static uint32_t ByteCountForInt(uint32_t value, bool isSigned);
50 };
51 } // namespace Telephony
52 } // namespace OHOS
53 #endif // ASN1_UTIL_H_
54