MySQL 8.4.2
Source Code Documentation
json_reader.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef JSON_READER_INCLUDED
25#define JSON_READER_INCLUDED
26
27#include <memory>
28#include <string>
29#include <vector>
30
31#define RAPIDJSON_HAS_STDSTRING 1
32
33#include "my_rapidjson_size_t.h"
34
35#include <rapidjson/document.h>
36#include <rapidjson/schema.h>
37
40
41#include "json_ds.h"
42
43namespace keyring_common {
44namespace json_data {
45
47 std::vector<std::pair<std::pair<meta::Metadata, data::Data>,
48 std::unique_ptr<Json_data_extension>>>;
49
50/**
51 Base Json_reader
52
53 Expected format for version 1.0
54 {
55 "version": "1.0",
56 "elements": [
57 {
58 "user": "<user_name>",
59 "data_id": "<name>",
60 "data_type": "<data_type>",
61 "data": "<hex_of_data>",
62 "extension": [
63 ]
64 },
65 ...
66 ...
67 ]
68 }
69*/
70
72 public:
73 Json_reader(const std::string schema, const std::string data,
74 const std::string version_key = "version",
75 const std::string array_key = "elements");
76
77 Json_reader(const std::string data);
78
80
81 /** Destructor */
82 virtual ~Json_reader() = default;
83
84 std::string version() const;
85
86 /**
87 Get number of elements in the document
88
89 @returns number elements in the document
90 */
91 size_t num_elements() const;
92
93 /**
94 Fetch element from given position
95
96 @param [in] index Element position
97 @param [out] metadata Data identifier
98 @param [out] data Data
99 @param [out] json_data_extension Backend specific extension
100
101 @return status of operation
102 @retval false Success
103 @retval true Failure
104 */
105 virtual bool get_element(
106 size_t index, meta::Metadata &metadata, data::Data &data,
107 std::unique_ptr<Json_data_extension> &json_data_extension) const;
108
109 /**
110 Get all elements
111
112 @param [out] output Output vector
113
114 @returns status of extracting elements
115 @retval false Success
116 @retval true Failure
117 */
118 virtual bool get_elements(output_vector &output) const;
119
120 bool valid() const { return valid_; }
121
122 private:
123 /** Data in JSON DOM format */
124 rapidjson::Document document_;
125 /** Version key */
126 const std::string version_key_;
127 /** user specific elements array key */
128 const std::string array_key_;
129 /** Validity of the data */
130 bool valid_;
131};
132
133} // namespace json_data
134
135} // namespace keyring_common
136
137#endif // !JSON_READER_INCLUDED
Sensitive data storage.
Definition: data.h:40
Base Json_reader.
Definition: json_reader.h:71
virtual ~Json_reader()=default
Destructor.
std::string version() const
Get version info.
Definition: json_reader.cc:118
bool valid() const
Definition: json_reader.h:120
virtual bool get_element(size_t index, meta::Metadata &metadata, data::Data &data, std::unique_ptr< Json_data_extension > &json_data_extension) const
Fetch element from given position.
Definition: json_reader.cc:133
virtual bool get_elements(output_vector &output) const
Get all elements.
Definition: json_reader.cc:151
size_t num_elements() const
Get number of elements in the document.
Definition: json_reader.cc:128
rapidjson::Document document_
Data in JSON DOM format.
Definition: json_reader.h:124
const std::string version_key_
Version key.
Definition: json_reader.h:126
Json_reader()
Definition: json_reader.cc:110
const std::string array_key_
user specific elements array key
Definition: json_reader.h:128
bool valid_
Validity of the data.
Definition: json_reader.h:130
Common metadata.
Definition: meta.h:39
Define rapidjson::SizeType to be std::size_t.
std::vector< std::pair< std::pair< meta::Metadata, data::Data >, std::unique_ptr< Json_data_extension > > > output_vector
Definition: json_reader.h:48
Definition: keyring_encryption_service_definition.h:32