Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
JsonUtils.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include <boost/json.hpp>
23#include <boost/json/object.hpp>
24
25#include <algorithm>
26#include <cctype>
27#include <string>
28
32namespace util {
33
40inline std::string
41toLower(std::string str)
42{
43 std::ranges::transform(str, std::begin(str), [](unsigned char c) { return std::tolower(c); });
44 return str;
45}
46
53inline std::string
54toUpper(std::string str)
55{
56 std::ranges::transform(str, std::begin(str), [](unsigned char c) { return std::toupper(c); });
57 return str;
58}
59
66inline boost::json::object
67removeSecret(boost::json::object const& object)
68{
69 auto newObject = object;
70 auto const secretFields = {"secret", "seed", "seed_hex", "passphrase"};
71
72 if (newObject.contains("params") and newObject.at("params").is_array() and
73 not newObject.at("params").as_array().empty() and newObject.at("params").as_array()[0].is_object()) {
74 for (auto const& secretField : secretFields) {
75 if (newObject.at("params").as_array()[0].as_object().contains(secretField))
76 newObject.at("params").as_array()[0].as_object()[secretField] = "*";
77 }
78 }
79
80 // for websocket requests
81 for (auto const& secretField : secretFields) {
82 if (newObject.contains(secretField))
83 newObject[secretField] = "*";
84 }
85
86 return newObject;
87}
88
89} // namespace util
This namespace contains various utilities.
Definition AccountUtils.hpp:30
std::string toUpper(std::string str)
Convert a string to uppercase.
Definition JsonUtils.hpp:54
boost::json::object removeSecret(boost::json::object const &object)
Removes any detected secret information from a response JSON object.
Definition JsonUtils.hpp:67
std::string toLower(std::string str)
Convert a string to lowercase.
Definition JsonUtils.hpp:41