1 /*
2  * Copyright (C) 2023 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 GSM_SMS_COMMON_UTILS_H
17 #define GSM_SMS_COMMON_UTILS_H
18 
19 #include <ctime>
20 
21 #include "sms_pdu_buffer.h"
22 #include "sms_pdu_code_type.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 class GsmSmsCommonUtils {
27 public:
28     GsmSmsCommonUtils() = default;
29     ~GsmSmsCommonUtils() = default;
30     bool Pack7bitChar(SmsWriteBuffer &buffer, const uint8_t *userData, uint8_t dataLen, uint8_t fillBits);
31     bool Unpack7bitChar(SmsReadBuffer &buffer, uint8_t dataLen, uint8_t fillBits, uint8_t *unpackData,
32         uint8_t unpackDataLen, uint8_t &dstIdx);
33     static bool Unpack7bitCharForMiddlePart(const uint8_t *buffer, uint8_t dataLen, uint8_t *unpackData);
34     bool DigitToBcd(const char *digit, uint8_t digitLen, uint8_t *bcd, uint8_t bcdLen, uint8_t &len);
35     bool BcdToDigit(const uint8_t *bcd, uint8_t bcdLen, std::string &digit, uint8_t maxDigitLen);
36 
37 private:
38     char BcdToChar(const uint8_t c);
39     bool Pack7bitCharPartData(SmsWriteBuffer &buffer, const uint8_t *userData, uint8_t &srcIdx, uint8_t &shift);
40 };
41 } // namespace Telephony
42 } // namespace OHOS
43 #endif