Fix static analysis issues
[platform/core/base/bundle.git] / src / key-info-internal.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef KEY_INFO_INTERNAL_H_
18 #define KEY_INFO_INTERNAL_H_
19
20 #include <string>
21 #include <vector>
22 #include <memory>
23
24 namespace tizen_base {
25 namespace internal {
26
27 class KeyInfo {
28  public:
29   KeyInfo(int type, std::string key,
30           std::vector<unsigned char> value);
31   KeyInfo(int type, std::string key,
32           std::vector<std::vector<unsigned char>> values);
33   explicit KeyInfo(std::vector<unsigned char> encoded_bytes);
34   virtual ~KeyInfo() = default;
35
36   KeyInfo(const KeyInfo& key_info);
37   KeyInfo& operator = (const KeyInfo& key_info);
38   KeyInfo(KeyInfo&& key_info) noexcept;
39   KeyInfo& operator = (KeyInfo&& key_info) noexcept;
40
41   bool operator == (const KeyInfo& key_info);
42
43   int GetType() const;
44   bool IsArray() const;
45   const std::string& GetKey();
46   const std::vector<std::unique_ptr<unsigned char[]>>& GetValues();
47   const std::vector<std::size_t>& GetValuesSize();
48   const std::vector<unsigned int>& GetUValuesSize();
49   std::vector<unsigned char> Encode();
50
51   int SetValue(int index, const std::vector<unsigned char>& value);
52   int GetSize() const;
53
54  private:
55   std::size_t GetEncodedSize();
56   int SetValuesSize();
57   int SetValue(const std::vector<unsigned char>& value);
58   int SetValues(const std::vector<std::vector<unsigned char>>& values);
59   int Decode(const std::vector<unsigned char>& bytes);
60
61  private:
62   int type_;
63   std::string key_;
64   std::vector<std::unique_ptr<unsigned char[]>> values_;
65   std::vector<std::size_t> values_size_;
66   std::vector<unsigned int> uvalues_size_;
67 };
68
69 }  // namespace internal
70 }  // namespace tizen_base
71
72 #endif  // KEY_INFO_INTERNAL_H_