• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SIM_NUMBER_DECODE_H
17 #define OHOS_SIM_NUMBER_DECODE_H
18 
19 #include <vector>
20 #include <regex>
21 #include "telephony_log_wrapper.h"
22 
23 namespace OHOS {
24 namespace Telephony {
25 const int MAX_NUMBER_CHAR = 20;
26 enum SectionPosition { POS_START = 1, POS_BRACE = 2, POS_BRACKET = 3, POS_PARENTHESIS = 4, POS_END = 5 };
27 enum CommonConstant { MIN_LENGTH = 2, SHIFT_FLAG = 4, CHAR_START = 0xa, HALF_BYTE = 0xf, BYTE_HIGH = 0xf0 };
28 
29 class SimNumberDecode final {
30 public:
31     const static int32_t BCD_TYPE_ADN = 1;
32     const static int32_t BCD_TYPE_CALLER = 2;
33 
34     static bool NumberConvertToBCD(const std::string &number, std::vector<uint8_t> &bcdCodes,
35         const bool includeLen = false, const int bcdExtType = BCD_TYPE_ADN);
36 
37     static bool BCDConvertToString(const std::vector<uint8_t>::const_iterator &codeBeg,
38         const std::vector<uint8_t>::const_iterator &codeEnd, std::string &number,
39         const int bcdExtType = BCD_TYPE_ADN);
40 
41     static std::string BCDConvertToString(const std::shared_ptr<unsigned char> bytesData, int offset, int length,
42         int bcdExtType = BCD_TYPE_ADN);
43 
44     static bool IsValidNumberString(const std::string &number);
45 
46 private:
47     static bool BCDSectionConvertToString(const std::vector<uint8_t>::const_iterator &codeBeg,
48         const std::vector<uint8_t>::const_iterator &codeEnd, std::string &number, const int bcdExtType);
49 
50     static bool CharToBCD(const char c, uint8_t &result, const int bcdExtType);
51 
52     static bool BcdToChar(const uint8_t bcdCode, char &result, const int bcdExtType);
53 
54     static const std::string *chooseExtendedByType(const int bcdExtType);
55 
56     static constexpr uint8_t FLAG_INTERNATIONAL = 0x91;
57     static constexpr uint8_t FLAG_UNKNOWN = 0x81;
58     inline const static std::string BCD_ADN_EXTENTION = "*#,N;";
59     inline const static std::string BCD_CALLER_EXTENTION = "*#abc";
60     inline constexpr static int INC_ONE = 1;
61     inline constexpr static size_t EVEN = 2;
62     inline constexpr static int INIT_VAL = 0;
63     inline constexpr static int FOUR_BIT = 4;
64     inline constexpr static uint8_t HI_FOUR = 0xf0;
65     inline constexpr static uint8_t LO_FOUR = 0x0f;
66 };
67 } // namespace Telephony
68 } // namespace OHOS
69 #endif // OHOS_SIM_NUMBER_DECODE_H