]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2601] decode64 and encode64 are now methods in TranslatorBasic
authorAndrei Pavel <andrei@isc.org>
Mon, 31 Oct 2022 12:00:39 +0000 (14:00 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 25 Nov 2022 16:15:33 +0000 (18:15 +0200)
src/lib/yang/translator.cc
src/lib/yang/translator.h

index 0d5d97d05f5a184b4037616cd272b6e0e435a069..9cfa804eb080289099c4f25cd3a455150a0b4a40 100644 (file)
@@ -19,26 +19,6 @@ using namespace isc::util::encode;
 using namespace libyang;
 using namespace sysrepo;
 
-namespace {
-
-string encode64(const string& input) {
-    vector<uint8_t> binary;
-    binary.resize(input.size());
-    memmove(&binary[0], input.c_str(), binary.size());
-    return (encodeBase64(binary));
-}
-
-string decode64(const string& input) {
-    vector<uint8_t> binary;
-    decodeBase64(input, binary);
-    string result;
-    result.resize(binary.size());
-    memmove(&result[0], &binary[0], result.size());
-    return (result);
-}
-
-} // end of anonymous namespace
-
 namespace isc {
 namespace yang {
 
@@ -69,6 +49,16 @@ void TranslatorBasic::checkAndSetLeaf(ConstElementPtr const& from,
     }
 }
 
+string
+TranslatorBasic::decode64(string const& input) {
+    vector<uint8_t> binary;
+    decodeBase64(input, binary);
+    string result;
+    result.resize(binary.size());
+    memmove(&result[0], &binary[0], result.size());
+    return (result);
+}
+
 void
 TranslatorBasic::deleteItem(const std::string& xpath) {
     /// @todo: Remove this if convenient. It is not strictly required and only done to detect
@@ -93,6 +83,15 @@ TranslatorBasic::deleteItem(const std::string& xpath) {
     session_.applyChanges();
 }
 
+
+string
+TranslatorBasic::encode64(string const& input) {
+    vector<uint8_t> binary;
+    binary.resize(input.size());
+    memmove(&binary[0], input.c_str(), binary.size());
+    return (encodeBase64(binary));
+}
+
 DataNode
 TranslatorBasic::findXPath(string const& xpath) {
     optional<DataNode> const& data_node(getNode(xpath));
index 51b1400b3090d05c0060e0b766d63ce61f7954f4..31d941efc793a62ebc643a6b7ef39beaa2b44665 100644 (file)
@@ -189,6 +189,21 @@ public:
                                                 libyang::LeafBaseType const type);
 
 protected:
+    /// @brief Decode a YANG element of binary type to a string that
+    /// can be stored in an Element::string JSON.
+    ///
+    /// @param input string to be decoded
+    ///
+    /// @return the decoded string
+    static std::string decode64(std::string const& input);
+
+    /// @brief Encode a string such that it can be stored in a YANG element of binary type.
+    ///
+    /// @param input string to be encoded
+    ///
+    /// @return the encoded string
+    static std::string encode64(std::string const& input);
+
     /// @brief The sysrepo session.
     sysrepo::Session session_;