• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BUILDER_H
17 #define ASN1_BUILDER_H
18 
19 #include <cstdbool>
20 #include <cstdint>
21 #include <list>
22 #include <mutex>
23 #include <vector>
24 #include "asn1_node.h"
25 #include "telephony_log_wrapper.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 class Asn1Builder {
30 public:
Asn1Builder(const uint32_t tag)31     explicit Asn1Builder(const uint32_t tag) : tag_(tag) {};
32     void Asn1AddChild(const std::shared_ptr<Asn1Node> node);
33     int32_t Asn1AddChildAsBytes(uint32_t tag, const std::vector<uint8_t> &childByte, uint32_t byteLen);
34     int32_t Asn1AddChildAsString(uint32_t tag, const std::string &childStr);
35     int32_t Asn1AddChildAsInteger(uint32_t tag, uint32_t childInt);
36     int32_t Asn1AddChildAsSignedInteger(uint32_t tag, int32_t childSignedInt);
37     int32_t Asn1AddChildAsBits(uint32_t tag, int32_t childBits);
38     int32_t Asn1AddChildAsBoolean(uint32_t tag, bool flag);
39     std::shared_ptr<Asn1Node> Asn1Build();
40     uint32_t Asn1BuilderToHexStr(std::string &destStr);
41 private:
42     uint32_t tag_ = 0;
43     std::list<std::shared_ptr<Asn1Node>> children_;
44     std::mutex mutex_;
45 };
46 } // namespace Telephony
47 } // namespace OHOS
48 #endif // ASN1_BUILDER_H