]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3209] Initial commit
authorThomas Markwalder <tmark@isc.org>
Mon, 29 Jan 2024 16:00:41 +0000 (11:00 -0500)
committerThomas Markwalder <tmark@isc.org>
Wed, 7 Feb 2024 13:58:47 +0000 (13:58 +0000)
Rewrote encoding/decoding.

src/lib/util/Makefile.am
    Removed old files, added encode.cc, encode.h

src/lib/util/encode/encode.*
    New implemenentation encoding and decoding not based
    on boost.

86 files changed:
src/bin/d2/tests/d2_cfg_mgr_unittests.cc
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
src/bin/perfdhcp/command_options.cc
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/hooks/dhcp/user_chk/user.cc
src/lib/config/base_command_mgr.cc
src/lib/cryptolink/tests/crypto_unittests.cc
src/lib/cryptolink/tests/hash_unittests.cc
src/lib/cryptolink/tests/hmac_unittests.cc
src/lib/d2srv/d2_cfg_mgr.cc
src/lib/d2srv/testutils/nc_test_utils.cc
src/lib/dhcp/option.cc
src/lib/dhcp/option6_auth.cc
src/lib/dhcp/option6_pdexclude.cc
src/lib/dhcp/option_custom.cc
src/lib/dhcp/option_data_types.cc
src/lib/dhcp/option_definition.cc
src/lib/dhcp/tests/duid_factory_unittest.cc
src/lib/dhcp/tests/libdhcp++_unittest.cc
src/lib/dhcp/tests/option6_pdexclude_unittest.cc
src/lib/dhcp/tests/option_vendor_unittest.cc
src/lib/dhcp/tests/pkt4_unittest.cc
src/lib/dhcp/tests/pkt6_unittest.cc
src/lib/dhcp/testutils/pkt_captures4.cc
src/lib/dhcp/testutils/pkt_captures6.cc
src/lib/dhcp_ddns/ncr_msg.cc
src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/cfg_duid.cc
src/lib/dhcpsrv/cfg_hosts.cc
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/lease_mgr.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/option_data_parser.cc
src/lib/dhcpsrv/tests/cfg_duid_unittest.cc
src/lib/dhcpsrv/tests/duid_config_parser_unittest.cc
src/lib/dhcpsrv/tests/host_unittest.cc
src/lib/dhcpsrv/tests/sanity_checks_unittest.cc
src/lib/dns/nsec3hash.cc
src/lib/dns/rdata.cc
src/lib/dns/rdata/any_255/tsig_250.cc
src/lib/dns/rdata/generic/detail/nsec3param_common.cc
src/lib/dns/rdata/generic/dlv_32769.cc
src/lib/dns/rdata/generic/dnskey_48.cc
src/lib/dns/rdata/generic/ds_43.cc
src/lib/dns/rdata/generic/nsec3_50.cc
src/lib/dns/rdata/generic/nsec3param_51.cc
src/lib/dns/rdata/generic/nsec_47.cc
src/lib/dns/rdata/generic/rrsig_46.cc
src/lib/dns/rdata/generic/sshfp_44.cc
src/lib/dns/rdata/generic/tkey_249.cc
src/lib/dns/rdata/generic/tlsa_52.cc
src/lib/dns/rdata/in_1/dhcid_49.cc
src/lib/dns/rdataclass.cc
src/lib/dns/tests/nsec3hash_unittest.cc
src/lib/dns/tests/rdata_dhcid_unittest.cc
src/lib/dns/tests/tsig_unittest.cc
src/lib/dns/tsigkey.cc
src/lib/eval/token.cc
src/lib/http/basic_auth.cc
src/lib/process/d_cfg_mgr.cc
src/lib/process/d_controller.cc
src/lib/util/Makefile.am
src/lib/util/encode/base16_from_binary.h [deleted file]
src/lib/util/encode/base32hex.h [deleted file]
src/lib/util/encode/base32hex_from_binary.h [deleted file]
src/lib/util/encode/base64.h [deleted file]
src/lib/util/encode/base_n.cc [deleted file]
src/lib/util/encode/binary_from_base16.h [deleted file]
src/lib/util/encode/binary_from_base32hex.h [deleted file]
src/lib/util/encode/encode.cc [new file with mode: 0644]
src/lib/util/encode/encode.h [new file with mode: 0644]
src/lib/util/encode/hex.h [deleted file]
src/lib/util/strutil.cc
src/lib/util/tests/base32hex_unittest.cc
src/lib/util/tests/base64_unittest.cc
src/lib/util/tests/hex_unittest.cc
src/lib/util/tests/strutil_unittest.cc
src/lib/yang/adaptor_host.cc
src/lib/yang/translator.cc

index 09cca5f5b2061b4d6a9aee3d6ab8a40843a82834..12c95a7f5ba3ef915a5d479870d1640c52aec15b 100644 (file)
@@ -15,7 +15,7 @@
 #include <dhcpsrv/testutils/config_result_check.h>
 #include <process/testutils/d_test_stubs.h>
 #include <test_data_files_config.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
index 5ab8ce3ac02e572b564e43e27c1024222fa8bd47..90dc449964fe179b5fa0cc013bb116308f87f1a5 100644 (file)
@@ -26,7 +26,7 @@
 #include <hooks/hooks_manager.h>
 #include <process/cfgrpt/config_report.h>
 #include <stats/stats_mgr.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/multi_threading_mgr.h>
 
 #include <signal.h>
index 1ae2c0a38227aae41214510f2ff10c182527577b..6164c3c7d9d26f92f77460edac53f5588b1986ea 100644 (file)
@@ -40,7 +40,7 @@
 #include <hooks/hooks_manager.h>
 #include <hooks/hooks_parser.h>
 #include <process/config_ctl_parser.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/multi_threading_mgr.h>
 #include <util/strutil.h>
 
index 545cbabb540a691fc4f926c9f735a80bc01de29e..521dad3124b8a2e8a483cad574e3f850028cbbc2 100644 (file)
@@ -34,7 +34,7 @@
 #include <dhcpsrv/host_mgr.h>
 #include <stats/stats_mgr.h>
 #include <testutils/gtest_utils.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #ifdef HAVE_MYSQL
 #include <mysql/testutils/mysql_schema.h>
index 4a6e4e84a9d008c31f8b987e1ae16a5877dd711e..fe4200a682cd22fedb1ab08e1e200d700966fc07 100644 (file)
@@ -26,7 +26,7 @@
 #include <hooks/hooks_manager.h>
 #include <process/cfgrpt/config_report.h>
 #include <stats/stats_mgr.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/multi_threading_mgr.h>
 
 #include <signal.h>
index 4a0e04516883f0039cc043d126db17e4bd53bfb1..25e357103001e62920a0a323dda4c596018a3294 100644 (file)
@@ -47,7 +47,7 @@
 #include <hooks/hooks_log.h>
 #include <hooks/hooks_manager.h>
 #include <stats/stats_mgr.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/io_utilities.h>
 #include <util/pointer_util.h>
 #include <util/range_utilities.h>
index 27f603bd9c06a4fadb418a319254d9d0d10864ca..8fd4e15743201c3bc10d25cf3831d3575206338d 100644 (file)
@@ -43,7 +43,7 @@
 #include <hooks/hooks_parser.h>
 #include <log/logger_support.h>
 #include <process/config_ctl_parser.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/multi_threading_mgr.h>
 #include <util/strutil.h>
 #include <util/triplet.h>
index 1e0d43e4b86777f72db50500266d5f3f6777ffbc..a7f6648fcbbd7d99348c0f022ce9e376a93b8876 100644 (file)
@@ -35,7 +35,7 @@
 #include <testutils/gtest_utils.h>
 #include <util/buffer.h>
 #include <util/range_utilities.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #ifdef HAVE_MYSQL
 #include <mysql/testutils/mysql_schema.h>
index fa6772e60db352a4c688d2fa6986e0b2c851c1c5..dca896939dc67ffa4d00ecfa44d1882dc5e4d617 100644 (file)
@@ -14,7 +14,7 @@
 #include <dhcp/duid.h>
 #include <dhcp/option.h>
 #include <process/cfgrpt/config_report.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <boost/lexical_cast.hpp>
 #include <boost/date_time/posix_time/posix_time.hpp>
index 9054831b30fee2790a1c3eee4f8bb5a81765fb14..534d6f55161ac0da6a7f360aff8fbfce7b5a5556 100644 (file)
@@ -27,7 +27,7 @@
 #include <lease_parser.h>
 #include <lease_cmds_log.h>
 #include <stats/stats_mgr.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/multi_threading_mgr.h>
 #include <util/strutil.h>
 
index df571cf57fb718605f781531b17369431f80820e..2c780de091f9fe5caefc42a736bed863066ea07e 100644 (file)
@@ -9,7 +9,7 @@
 #include <dhcp/hwaddr.h>
 #include <dhcp/duid.h>
 #include <exceptions/exceptions.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <user.h>
 
index 4963afa37ff6bb124f35e29b8f951523bc741768..064303b841629d1b1b8a1ef689bc771df253c255 100644 (file)
@@ -12,7 +12,7 @@
 #include <cryptolink/crypto_hash.h>
 #include <hooks/callout_handle.h>
 #include <hooks/hooks_manager.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 #include <functional>
 #include <vector>
index 9edb52d4a6ee530f9841ca07e9186d079664dc3e..54c5c9af639c2dde64fe5ec297c689ee3ce4cdb4 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <gtest/gtest.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <cryptolink/cryptolink.h>
 #include <cryptolink/crypto_rng.h>
index d2e93968cfaa22c2e71da35099c94159ffcc6ae6..0500c35107608cf336be9bc77d41318d23d08a1e 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <gtest/gtest.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <cryptolink/cryptolink.h>
 #include <cryptolink/crypto_hash.h>
index d0c5cd9b45311e260d6bb20c0a1f70016402e2d9..0fabf92640ff7d66c544d2a4df844ebc335ae276 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <gtest/gtest.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <cryptolink/cryptolink.h>
 #include <cryptolink/crypto_hmac.h>
index 0244672483512f7d5f859f5347fed5d8a363b461..bf7df10dee855686c17ee41dac3ce8b07fb6915b 100644 (file)
@@ -11,7 +11,7 @@
 #include <d2srv/d2_simple_parser.h>
 #include <cc/command_interpreter.h>
 #include <config/base_command_mgr.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <boost/range/adaptor/reversed.hpp>
 
 using namespace isc::asiolink;
index 94cc2e61765e85e40a6031327c0650019813572b..b0f47c18e445bd6935df7a8b6cf2fa04066489fe 100644 (file)
@@ -11,7 +11,7 @@
 #include <d2srv/testutils/nc_test_utils.h>
 #include <dns/messagerenderer.h>
 #include <dns/opcode.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 
 #include <gtest/gtest.h>
 
index 95353efb98af0bae8f4ac0aa054e0cb3d3eda6ab..8e9a03a505079cc8b1785b85f273419066a55ff8 100644 (file)
@@ -10,7 +10,7 @@
 #include <dhcp/option.h>
 #include <dhcp/option_space.h>
 #include <exceptions/exceptions.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/io_utilities.h>
 
 #include <boost/make_shared.hpp>
index 4b5806d98f97a3ca0f71a946dbff4247a8ea90da..8ce63a1c8d7a289c98eb0863a8367166a7528f8f 100644 (file)
@@ -11,7 +11,7 @@
 #include <dhcp/option_space.h>
 #include <exceptions/exceptions.h>
 #include <util/io_utilities.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <sstream>
 #include <stdint.h>
index b71a820cbea56dd23e43f99a1e4786b792c728f9..4e785e5db7f015e9afd533eea3807c43b15aa477 100644 (file)
@@ -10,7 +10,7 @@
 #include <dhcp/dhcp6.h>
 #include <dhcp/option6_pdexclude.h>
 #include <exceptions/exceptions.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/io_utilities.h>
 
 #include <boost/dynamic_bitset.hpp>
index 08c3c74be895970e4110ddb98593ae43ecaace53..f1a4b04105756e8b90763c4d39c2efe3f6e03122 100644 (file)
@@ -9,7 +9,7 @@
 #include <dhcp/option_data_types.h>
 #include <dhcp/option_custom.h>
 #include <exceptions/isc_assert.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 using namespace isc::asiolink;
 
index 60aa9c3b191c81de3b5e78209db0c9cb154002fb..0308d8c6a3489a11e25cd5885dd0e7f0eee92b10 100644 (file)
@@ -10,7 +10,7 @@
 #include <dns/labelsequence.h>
 #include <dns/name.h>
 #include <util/strutil.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <algorithm>
 #include <limits>
 
index 4f0d1882801cfefaa78738360a9a9edd17df566d..d07d61da71d9f6e0b0489fca0df27a9d48a5f7b8 100644 (file)
@@ -28,7 +28,7 @@
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
 #include <dhcp/option_vendor_class.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <dns/labelsequence.h>
 #include <dns/name.h>
 #include <util/strutil.h>
index 824930c09b68356cedc0b2f4207773f8792e5abd..5a7a400c21cad51dfd8845a3250dd1ebc8e6df80 100644 (file)
@@ -9,7 +9,7 @@
 #include <dhcp/duid_factory.h>
 #include <dhcp/testutils/iface_mgr_test_config.h>
 #include <testutils/io_utils.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/range_utilities.h>
 #include <boost/algorithm/string.hpp>
 #include <gtest/gtest.h>
index 327b0dba99941b9dd1d844fad671484d257ab8dd..f6f262aeef0b042102e0573d2973234556de5a63 100644 (file)
@@ -28,7 +28,7 @@
 #include <dhcp/option_vendor.h>
 #include <dhcp/option_vendor_class.h>
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/thread_pool.h>
 
 #include <boost/pointer_cast.hpp>
index b119fc2a5be7f48e96e0c85c0fd37a7c121cf8fc..c1da0e106691b054f614d218d298570de4eaa7b4 100644 (file)
@@ -12,7 +12,7 @@
 #include <exceptions/exceptions.h>
 #include <dhcp/option6_pdexclude.h>
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <gtest/gtest.h>
 
 using namespace isc;
index bb764004f471f53729842596361342ae5a0ef9aa..906cb6efd81fbc708445445b69f3223c204e35ae 100644 (file)
@@ -15,7 +15,7 @@
 #include <dhcp/option_int_array.h>
 #include <exceptions/exceptions.h>
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
index cf82aad05c8bd1062b062ada38668a2bc056e5a5..db07f2bd5845a6c39fc947afe34838ff3ba8f0bc 100644 (file)
@@ -19,7 +19,7 @@
 #include <exceptions/exceptions.h>
 #include <testutils/gtest_utils.h>
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <boost/shared_array.hpp>
 #include <boost/shared_ptr.hpp>
index 280bb6447a3cef16e8cf21c7ddded10d6d05fd1d..eee590883c4d37956702c141ec9e52724c24d7e1 100644 (file)
@@ -28,7 +28,7 @@
 #include <boost/range/adaptor/reversed.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/pointer_cast.hpp>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <gtest/gtest.h>
 
 #include <algorithm>
index aa1033e35ddba55f25b17952953092481995e28a..81cc85509acf0a1d2e144511bd2bff3bc7fbe6fb 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <asiolink/io_address.h>
 #include <dhcp/testutils/pkt_captures.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <string>
 
index 5a0c45bb04dbbd5d662d803590d9e4003149f0bc..72e23886ec88210dac74101fb58c72ec15375b9f 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <dhcp/pkt6.h>
 #include <dhcp/testutils/pkt_captures.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <string>
 
index 95afc5fc6eb197815124af20dbf0313dfa504d31..82c3ba9ae3d61e3034055cbbf18dc4e502ee4e5d 100644 (file)
@@ -11,7 +11,7 @@
 #include <asiolink/io_error.h>
 #include <cryptolink/cryptolink.h>
 #include <cryptolink/crypto_hash.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <boost/algorithm/string/predicate.hpp>
 
index bbbb2fa04bcadc2e61d9d2b3240c587c418e9400..a10c0c54371222b9b5fec42f12c53c6fccea4802 100644 (file)
@@ -28,7 +28,7 @@
 #include <hooks/hooks_manager.h>
 #include <dhcpsrv/callout_handle_store.h>
 #include <stats/stats_mgr.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/stopwatch.h>
 #include <hooks/server_hooks.h>
 
index fe17f208cbfc5082fbfdf5d1196631faad19019e..6a440003ddb9dec3e7b7ec0f9349a43b025481a9 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <dhcp/duid_factory.h>
 #include <dhcpsrv/cfg_duid.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/strutil.h>
 #include <iostream>
 #include <string>
index 168e2a16f0fcff67f54cd292e136b4ef93248f26..433aabe2e903d3e2a1da3705fff4de58f1728e93 100644 (file)
@@ -12,7 +12,7 @@
 #include <dhcpsrv/hosts_log.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <exceptions/exceptions.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <boost/foreach.hpp>
 #include <ostream>
 #include <string>
index 7c2a7dd4364823b1ea07b0ab61d885abe7dd40e8..27ae10b14e234d3ed1ca9e27b82063a668803ed6 100644 (file)
@@ -10,7 +10,7 @@
 #include <dhcpsrv/cfg_option.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/option_space.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/make_shared.hpp>
index 47502c0f9e75e5207a40536089adc5fb006e45c8..4390dba32269b23e23b89b3247870af1abd50589 100644 (file)
@@ -13,7 +13,7 @@
 #include <dhcpsrv/host.h>
 #include <exceptions/exceptions.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/strutil.h>
 
 #include <boost/foreach.hpp>
index 6f764aec0e618494ac37efb7950cf0ef32674856..38164ce0e4383ca04bced3f3fc415589b54bc5ce 100644 (file)
@@ -13,7 +13,7 @@
 #include <dhcpsrv/lease_mgr.h>
 #include <exceptions/exceptions.h>
 #include <stats/stats_mgr.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <boost/algorithm/string.hpp>
 
index 7f44cc4e75ad0958cb46df0f13b6a039112f4dde..78077b5986964bffe242eac421764297c65d4ce5 100644 (file)
@@ -18,7 +18,7 @@
 #include <dhcpsrv/parsers/simple_parser4.h>
 #include <dhcpsrv/parsers/simple_parser6.h>
 #include <dhcpsrv/cfg_mac_source.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/strutil.h>
 
 #include <boost/algorithm/string.hpp>
index d1211d55160a3845a018ca17352c83612d900f86..8ec49a03096c5c72c1630a2c7381a5671f05c664 100644 (file)
@@ -15,7 +15,7 @@
 #include <dhcpsrv/parsers/option_data_parser.h>
 #include <dhcpsrv/parsers/simple_parser4.h>
 #include <dhcpsrv/parsers/simple_parser6.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/strutil.h>
 #include <boost/make_shared.hpp>
 #include <limits>
index 10da5b9b4fd88f61b442fca4774aea96d2190957..939a9a84f03468ecaec8b6fb1c61be843e2a3d68 100644 (file)
@@ -11,7 +11,7 @@
 #include <exceptions/exceptions.h>
 #include <testutils/io_utils.h>
 #include <testutils/test_to_element.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <gtest/gtest.h>
 #include <stdint.h>
 #include <stdio.h>
index be7e96bf9b87913deaa3958b0a7756a66ee2f7d6..79de77e4609291814e412399fffad279e9a6f8fb 100644 (file)
@@ -12,7 +12,7 @@
 #include <dhcpsrv/parsers/dhcp_parsers.h>
 #include <dhcpsrv/testutils/config_result_check.h>
 #include <testutils/test_to_element.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <gtest/gtest.h>
 #include <limits>
 #include <sstream>
index ae1fdd096f4a54844761bd815d1d89e4f24f0666..4ac51e112bb281714f235e8e0bf28dc171bdfd08 100644 (file)
@@ -9,7 +9,7 @@
 #include <dhcpsrv/host.h>
 #include <dhcp/option_space.h>
 #include <testutils/gtest_utils.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/range_utilities.h>
 #include <boost/foreach.hpp>
 #include <boost/scoped_ptr.hpp>
@@ -1443,7 +1443,7 @@ TEST(AuthKeyTest, basicTest) {
     ASSERT_EQ(key16ByteStr, defaultTestKey.toText());
     ASSERT_EQ(key16ByteBin, defaultTestKey.getAuthKey());
 
-    string expected = "bad auth key: attempt to decode a value not in base16 char set";
+    string expected = "bad auth key: attempt to decode a value not in base16 char set: 0123456789abcdefgh";
     ASSERT_THROW_MSG(defaultTestKey.setAuthKey(key18ByteStr),
                      BadValue, expected);
 }
index 7185b931ae3337017c7beb1cdd7fa393276d24ca..df297ea5ce87b2e07f2fb2bcc7b397601dd2ce78 100644 (file)
@@ -886,7 +886,7 @@ TEST_F(ExtendedInfoChecksTest, badEncodingRemoteId4strict) {
            { "DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL"
              " extended info for lease 192.168.1.1 failed checks"
              " (in remote-id a problem was found:"
-             " attempt to decode a value not in base16 char set)" });
+             " attempt to decode a value not in base16 char set: foo)" });
 }
 
 // Empty remote-id entry is right up to the fix sanity level.
@@ -965,7 +965,7 @@ TEST_F(ExtendedInfoChecksTest, badEncodingRelayId4strict) {
            { "DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL"
              " extended info for lease 192.168.1.1 failed checks"
              " (in relay-id a problem was found:"
-             " attempt to decode a value not in base16 char set)" });
+             " attempt to decode a value not in base16 char set: foo)" });
 }
 
 // Empty relay-id entry is right up to the fix sanity level.
@@ -1409,7 +1409,7 @@ TEST_F(ExtendedInfoChecksTest, badEncodingRemoteId6strict) {
            { "DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL"
              " extended info for lease 2001::1 failed checks"
              " (in remote-id [relay#0] a problem was found:"
-             " attempt to decode a value not in base16 char set)" });
+             " attempt to decode a value not in base16 char set: foo)" });
 }
 
 // Empty remote-id entry is dropped at strict or higher sanity levels.
@@ -1470,7 +1470,7 @@ TEST_F(ExtendedInfoChecksTest, badEncodingRelayId6strict) {
            { "DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL"
              " extended info for lease 2001::1 failed checks"
              " (in relay-id [relay#0] a problem was found:"
-             " attempt to decode a value not in base16 char set)" });
+             " attempt to decode a value not in base16 char set: foo)" });
 }
 
 // Empty relay-id entry is dropped at strict or higher sanity levels.
index a0049152e508d04ccb9bf47cf150c38c123e1e7a..83e7d70c78aad45b952548192659d63418ce2513 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2023 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -20,7 +20,7 @@
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/base32hex.h>
+#include <util/encode/encode.h>
 
 #include <cryptolink/cryptolink.h>
 #include <cryptolink/crypto_hash.h>
index 357ccc7cdf0b4933c90a7cdcc962334576db3b8e..45e9a3ed1c958031b01eb3b12e629a1e9809cff7 100644 (file)
@@ -9,7 +9,7 @@
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
index a80d742d097cc9b95534eba9bd45c076cfd83345..4b20fd643d7e0714bc4c6a539834cabd093390f1 100644 (file)
@@ -13,7 +13,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include <util/buffer.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
index efe488a8a1e30e62513786ef0ba5dcf79de00ae9..cc90558ff851230a4153acca89ca116beb7eb3e7 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 
 #include <dns/exceptions.h>
index 66303b7a57ecaf0fdb6dfd4f1830d8f0d64b9d0d..78424cc0dbedc46f5f4aad69aa620db57f69b134 100644 (file)
@@ -9,7 +9,7 @@
 #include <string>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
index df5d8333942e281f517cba4418cedec7c0304422..ec7668b7cc131a32a9ea707feee35ceee15f98e5 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
index 48c421c4d86ea3da7599d401e6d8bd848f32838e..5f193c508a42a753e574751d5992d47232431204 100644 (file)
@@ -9,7 +9,7 @@
 #include <string>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
index e99c109807bff0528b638a45dad1dc3149ee4450..2de3fd6e4899d7df698e050ba0b2f67ceb793a36 100644 (file)
@@ -15,8 +15,7 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <util/encode/base32hex.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 
 #include <dns/exceptions.h>
index 2d28a6988581f945fd9a97e185b6222848928ba7..883291a222b9907be790a1be60e06ff6c950c921 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
index f8af0e0142b4909df79b6caaaf657dce3edce7a5..d3c7bac3ce34c9eb6b44211bb1ebcdf46acc0e6d 100644 (file)
@@ -11,7 +11,7 @@
 #include <sstream>
 #include <vector>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
index de92c67c3469f348e51639c6508a0edcca022c14..da5f1f63f79dc8243268f228c44fc7f106375e75 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 #include <util/time_utilities.h>
 #include <dns/messagerenderer.h>
index a08a17fcb0c453f07324a9c4db15f61a2e6819b7..7ac36a3581d4a4aae4695f603a63e2c01d35d71b 100644 (file)
@@ -11,7 +11,7 @@
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
index 435a345ac5a86d7c86f20994ef49afcaec9eb595..cace535a48786767cb5134194359cb1d0b862be5 100644 (file)
@@ -13,7 +13,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include <util/buffer.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/time_utilities.h>
 
 #include <dns/messagerenderer.h>
index 330b7a2c829886f94a6cb832e83ff19b5a1388ef..94183d4127c143d0e850f242a4ee2d324a9557e2 100644 (file)
@@ -11,7 +11,7 @@
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
index 57c79c2d23cb4b37a6f073f95ffef67012e878d8..4d36b278ef40d31bf39710763e81baa26a37754f 100644 (file)
@@ -12,7 +12,7 @@
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
index d27d65f743fa7f03fd3b5b8fe48ef82dc131795d..d9cb93f50c3933e2b4fed88bc35b8b040596d954 100644 (file)
@@ -20,7 +20,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include <util/buffer.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
@@ -1291,7 +1291,7 @@ CNAME::getCname() const {
 #include <string>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -1550,7 +1550,7 @@ DNAME::getDname() const {
 
 #include <boost/lexical_cast.hpp>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 #include <dns/messagerenderer.h>
 #include <dns/name.h>
@@ -1865,7 +1865,7 @@ DNSKEY::getAlgorithm() const {
 #include <string>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -2846,8 +2846,7 @@ NS::getNSName() const {
 
 #include <boost/lexical_cast.hpp>
 
-#include <util/encode/base32hex.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 
 #include <dns/exceptions.h>
@@ -3185,7 +3184,7 @@ NSEC3::getNext() const {
 #include <config.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -3425,7 +3424,7 @@ NSEC3PARAM::getSalt() const {
 #include <sstream>
 #include <vector>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
@@ -4160,7 +4159,7 @@ RP::compare(const Rdata& other) const {
 
 #include <boost/lexical_cast.hpp>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/buffer.h>
 #include <util/time_utilities.h>
 #include <dns/messagerenderer.h>
@@ -4852,7 +4851,7 @@ SPF::compare(const Rdata& other) const {
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -5156,7 +5155,7 @@ SSHFP::getFingerprintLength() const {
 #include <boost/lexical_cast.hpp>
 
 #include <util/buffer.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/time_utilities.h>
 
 #include <dns/messagerenderer.h>
@@ -5771,7 +5770,7 @@ TKEY::getOtherData() const {
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <dns/name.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
@@ -6620,7 +6619,7 @@ AAAA::compare(const Rdata& other) const {
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <dns/exceptions.h>
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
index b47bb4969bebca7039e05b3833d22c2b2052bddd..b447fa443a9e74774f0f1d0f2bc31e67b7a53ac4 100644 (file)
@@ -15,7 +15,7 @@
 #include <dns/nsec3hash.h>
 #include <dns/labelsequence.h>
 #include <dns/rdataclass.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 using boost::scoped_ptr;
 using namespace std;
index a96c3e4547e10c44bd24ffb503c6cb713e486a48..e603ff45b5555c3ff7c1244ee998c14fc1ed58f9 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <util/buffer.h>
 #include <dns/rdataclass.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 
 #include <gtest/gtest.h>
 
index fde67bc1e0fcf3affab45236f0573d80fc30c66c..2e58ca7c8c9919b6af5b6026bfcba74853ed3ed2 100644 (file)
@@ -18,7 +18,7 @@
 #include <exceptions/exceptions.h>
 
 #include <util/buffer.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/unittests/newhook.h>
 #include <util/time_utilities.h>
 
index ad94b623cba9d98c1be43354ad94f6e02a30a821..9f1eaf31ab8b4d0196e7ccbd61514b3f286dea99 100644 (file)
@@ -16,7 +16,7 @@
 #include <cryptolink/cryptolink.h>
 
 #include <dns/name.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <dns/tsigkey.h>
 
 #include <boost/lexical_cast.hpp>
index ff965d33f9ca480ca7c651e129621e5ab40d3eb2..45b11db57f543fec1c70f21a3902b1b92f621d15 100644 (file)
@@ -9,7 +9,7 @@
 #include <eval/token.h>
 #include <eval/eval_log.h>
 #include <eval/eval_context.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/io_utilities.h>
 #include <asiolink/io_address.h>
 #include <dhcp/pkt4.h>
index f3a1d871efaf309cb8445d939ed9d36472f1a307..2f048c939aaf5f732301d97f390344a45ccf408d 100644 (file)
@@ -7,7 +7,7 @@
 #include <config.h>
 
 #include <http/basic_auth.h>
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <util/encode/utf8.h>
 
 using namespace isc::util::encode;
index 8af77d08b25d95f991dd4189820d73daf93dd0c6..24ead16d3b9a1f7640251151d361aa5c3f59eb0d 100644 (file)
@@ -12,7 +12,7 @@
 #include <process/d_cfg_mgr.h>
 #include <process/daemon.h>
 #include <process/redact_config.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/strutil.h>
 
 #include <boost/lexical_cast.hpp>
index 5ec51ba7bcc9acfe8d5f2bc122d6e8a1e65cb9fe..7946a5c66dc97474ef0f15cf8e5a5bbb13b13bbe 100644 (file)
@@ -13,7 +13,7 @@
 #include <hooks/hooks_manager.h>
 #include <log/logger.h>
 #include <log/logger_support.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <process/daemon.h>
 #include <process/d_log.h>
 #include <process/d_controller.h>
index 5db89b67d71ea1b8000053f2146a4adfb96fbdeb..c7bd3214f48d45cc9043986e0dda3bcf436a21e1 100644 (file)
@@ -40,12 +40,7 @@ libkea_util_la_SOURCES += unlock_guard.h
 libkea_util_la_SOURCES += versioned_csv_file.h versioned_csv_file.cc
 libkea_util_la_SOURCES += watch_socket.cc watch_socket.h
 libkea_util_la_SOURCES += watched_thread.cc watched_thread.h
-libkea_util_la_SOURCES += encode/base16_from_binary.h
-libkea_util_la_SOURCES += encode/base32hex.h encode/base64.h
-libkea_util_la_SOURCES += encode/base32hex_from_binary.h
-libkea_util_la_SOURCES += encode/base_n.cc encode/hex.h
-libkea_util_la_SOURCES += encode/binary_from_base32hex.h
-libkea_util_la_SOURCES += encode/binary_from_base16.h
+libkea_util_la_SOURCES += encode/encode.cc encode/encode.h
 libkea_util_la_SOURCES += encode/utf8.cc encode/utf8.h
 
 libkea_util_la_LIBADD = $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
@@ -94,13 +89,7 @@ libkea_util_include_HEADERS = \
 
 libkea_util_encode_includedir = $(pkgincludedir)/util/encode
 libkea_util_encode_include_HEADERS = \
-       encode/base16_from_binary.h \
-       encode/base32hex.h \
-       encode/base32hex_from_binary.h \
-       encode/base64.h \
-       encode/binary_from_base16.h \
-       encode/binary_from_base32hex.h \
-       encode/hex.h \
+       encode/encode.h \
        encode/utf8.h
 
 libkea_util_io_includedir = $(pkgincludedir)/util/io
diff --git a/src/lib/util/encode/base16_from_binary.h b/src/lib/util/encode/base16_from_binary.h
deleted file mode 100644 (file)
index 3eb697d..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-#ifndef BOOST_ARCHIVE_ITERATORS_BASE16_FROM_BINARY_HPP
-#define BOOST_ARCHIVE_ITERATORS_BASE16_FROM_BINARY_HPP
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// base16_from_binary.h (derived from boost base64_from_binary.hpp)
-
-// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
-// Use, modification and distribution is subject to the Boost Software
-// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-//  See http://www.boost.org for updates, documentation, and revision history.
-
-#include <exceptions/isc_assert.h>
-
-#include <cstddef> // size_t
-#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
-#if defined(BOOST_NO_STDC_NAMESPACE)
-namespace std{ 
-    using ::size_t; 
-} // namespace std
-#endif
-
-// See base32hex_from_binary.h for why we need base64_from...hpp here.
-#include <boost/archive/iterators/base64_from_binary.hpp>
-
-namespace boost { 
-namespace archive {
-namespace iterators {
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// convert binary integers to base16 characters
-
-namespace detail {
-
-template<class CharType>
-struct from_4_bit {
-    typedef CharType result_type;
-    CharType operator()(CharType t) const{
-        const char * lookup_table = 
-            "0123456789"
-            "ABCDEF";
-        isc_throw_assert(t < 16);
-        return (lookup_table[static_cast<size_t>(t)]);
-    }
-};
-
-} // namespace detail
-
-// note: what we would like to do is
-// template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
-//  typedef transform_iterator<
-//      from_4_bit<CharType>,
-//      transform_width<Base, 4, sizeof(Base::value_type) * 8, CharType>
-//  > base16_from_binary;
-// but C++ won't accept this.  Rather than using a "type generator" and
-// using a different syntax, make a derivation which should be equivalent.
-//
-// Another issue addressed here is that the transform_iterator doesn't have
-// a templated constructor.  This makes it incompatible with the dataflow
-// ideal.  This is also addressed here.
-
-//template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
-template<
-    class Base, 
-    class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
->
-class base16_from_binary : 
-    public transform_iterator<
-        detail::from_4_bit<CharType>,
-        Base
-    >
-{
-    friend class boost::iterator_core_access;
-    typedef transform_iterator<
-        BOOST_DEDUCED_TYPENAME detail::from_4_bit<CharType>,
-        Base
-    > super_t;
-
-public:
-    // make composable by using templated constructor
-    template<class T>
-    base16_from_binary(T start) :
-        super_t(
-            Base(static_cast<T>(start)),
-            detail::from_4_bit<CharType>()
-        )
-    {}
-    // intel 7.1 doesn't like default copy constructor
-    base16_from_binary(const base16_from_binary & rhs) : 
-        super_t(
-            Base(rhs.base_reference()),
-            detail::from_4_bit<CharType>()
-        )
-    {}
-//    base16_from_binary(){};
-};
-
-} // namespace iterators
-} // namespace archive
-} // namespace boost
-
-#endif // BOOST_ARCHIVE_ITERATORS_BASE16_FROM_BINARY_HPP
diff --git a/src/lib/util/encode/base32hex.h b/src/lib/util/encode/base32hex.h
deleted file mode 100644 (file)
index 0a85b36..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (C) 2009-2015 Internet Systems Consortium, Inc. ("ISC")
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef BASE32HEX_H
-#define BASE32HEX_H 1
-
-#include <stdint.h>
-#include <string>
-#include <vector>
-
-//
-// Note: this helper module isn't specific to the DNS protocol per se.
-// We should probably move this to somewhere else, possibly in some common
-// utility area.
-//
-
-namespace isc {
-namespace util {
-namespace encode {
-
-/// \brief Encode binary data in the base32hex format.
-///
-/// The underlying implementation is shared with \c encodeBase64, and all
-/// description except the format (base32hex) equally applies.
-///
-/// Note: the encoding format is base32hex, not base32.
-///
-/// \param binary A vector object storing the data to be encoded. 
-/// \return A newly created string that stores base32hex encoded value for
-/// binary.
-std::string encodeBase32Hex(const std::vector<uint8_t>& binary);
-
-/// \brief Decode a text encoded in the base32hex format into the
-/// original %data.
-///
-/// The underlying implementation is shared with \c decodeBase64, and all
-/// description except the format (base32hex) equally applies.
-///
-/// Note: the encoding format is base32hex, not base32.
-///
-/// \param input A text encoded in the base32hex format.
-/// \param result A vector in which the decoded %data is to be stored.
-void decodeBase32Hex(const std::string& input, std::vector<uint8_t>& result);
-
-} // namespace encode 
-} // namespace util
-} // namespace isc
-
-#endif  // BASE32HEX_H
-
-// Local Variables:
-// mode: c++
-// End:
diff --git a/src/lib/util/encode/base32hex_from_binary.h b/src/lib/util/encode/base32hex_from_binary.h
deleted file mode 100644 (file)
index 84f2b69..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
-#define BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// base32hex_from_binary.h (derived from boost base64_from_binary.hpp)
-
-// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
-// Use, modification and distribution is subject to the Boost Software
-// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-//  See http://www.boost.org for updates, documentation, and revision history.
-
-#include <exceptions/isc_assert.h>
-
-#include <cstddef> // size_t
-#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
-#if defined(BOOST_NO_STDC_NAMESPACE)
-namespace std{ 
-    using ::size_t; 
-} // namespace std
-#endif
-
-// We use the same boost header files used in "base64_from_".  Since the
-// precise path to these headers may vary depending on the boost version we
-// simply include the base64 header here.
-#include <boost/archive/iterators/base64_from_binary.hpp>
-
-namespace boost { 
-namespace archive {
-namespace iterators {
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// convert binary integers to base32hex characters
-
-namespace detail {
-
-template<class CharType>
-struct from_5_bit {
-    typedef CharType result_type;
-    CharType operator()(CharType t) const{
-        const char * lookup_table = 
-            "0123456789"
-            "ABCDEFGHIJKLMNOPQRSTUV";
-        isc_throw_assert(t < 32);
-        return (lookup_table[static_cast<size_t>(t)]);
-    }
-};
-
-} // namespace detail
-
-// note: what we would like to do is
-// template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
-//  typedef transform_iterator<
-//      from_5_bit<CharType>,
-//      transform_width<Base, 5, sizeof(Base::value_type) * 8, CharType>
-//  > base32hex_from_binary;
-// but C++ won't accept this.  Rather than using a "type generator" and
-// using a different syntax, make a derivation which should be equivalent.
-//
-// Another issue addressed here is that the transform_iterator doesn't have
-// a templated constructor.  This makes it incompatible with the dataflow
-// ideal.  This is also addressed here.
-
-//template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
-template<
-    class Base, 
-    class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
->
-class base32hex_from_binary : 
-    public transform_iterator<
-        detail::from_5_bit<CharType>,
-        Base
-    >
-{
-    friend class boost::iterator_core_access;
-    typedef transform_iterator<
-        BOOST_DEDUCED_TYPENAME detail::from_5_bit<CharType>,
-        Base
-    > super_t;
-
-public:
-    // make composable by using templated constructor
-    template<class T>
-    base32hex_from_binary(T start) :
-        super_t(
-            Base(static_cast<T>(start)),
-            detail::from_5_bit<CharType>()
-        )
-    {}
-    // intel 7.1 doesn't like default copy constructor
-    base32hex_from_binary(const base32hex_from_binary & rhs) : 
-        super_t(
-            Base(rhs.base_reference()),
-            detail::from_5_bit<CharType>()
-        )
-    {}
-//    base32hex_from_binary(){};
-};
-
-} // namespace iterators
-} // namespace archive
-} // namespace boost
-
-#endif // BOOST_ARCHIVE_ITERATORS_BASE32HEX_FROM_BINARY_HPP
diff --git a/src/lib/util/encode/base64.h b/src/lib/util/encode/base64.h
deleted file mode 100644 (file)
index 84280ec..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (C) 2009-2015 Internet Systems Consortium, Inc. ("ISC")
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef BASE64_H
-#define BASE64_H 1
-
-#include <stdint.h>
-#include <string>
-#include <vector>
-
-//
-// Note: this helper module isn't specific to the DNS protocol per se.
-// We should probably move this to somewhere else, possibly in some common
-// utility area.
-//
-
-namespace isc {
-namespace util {
-namespace encode {
-
-/// \brief Encode binary data in the base64 format.
-///
-/// This function returns a new \c std::string object that stores a text
-/// encoded in the base64 format for the given \c binary %data.
-/// The resulting string will be a valid, canonical form of base64
-/// representation as specified in RFC4648.
-///
-/// If memory allocation for the returned string fails, a corresponding
-/// standard exception will be thrown.  This function never throws exceptions
-/// otherwise.
-///
-/// \param binary A vector object storing the data to be encoded. 
-/// \return A newly created string that stores base64 encoded value for binary.
-std::string encodeBase64(const std::vector<uint8_t>& binary);
-
-/// \brief Decode a text encoded in the base64 format into the original %data.
-///
-/// The \c input argument must be a valid string represented in the base64
-/// format as specified in RFC4648.  Space characters (spaces, tabs, newlines)
-/// can be included in \c input and will be ignored.  Without spaces, the
-/// length of string must be a multiple of 4 bytes with necessary paddings.
-/// Also it must be encoded using the canonical encoding (see RFC4648).
-/// If any of these conditions is not met, an exception of class
-/// \c isc::BadValue will be thrown.
-///
-/// If \c result doesn't have sufficient capacity to store all decoded %data
-/// and memory allocation fails, a corresponding standard exception will be
-/// thrown.  If the caller knows the necessary length (which can in theory
-/// be calculated from the input string), this situation can be avoided by
-/// reserving sufficient space for \c result beforehand.
-///
-/// Any existing %data in \c result will be removed.  This is the case in some
-/// of the cases where an exception is thrown; that is, this function only
-/// provides the basic exception guarantee.
-///
-/// \param input A text encoded in the base64 format.
-/// \param result A vector in which the decoded %data is to be stored.
-void decodeBase64(const std::string& input, std::vector<uint8_t>& result);
-
-} // namespace encode
-} // namespace util
-} // namespace isc
-
-#endif  // BASE64_H
-
-// Local Variables: 
-// mode: c++
-// End: 
diff --git a/src/lib/util/encode/base_n.cc b/src/lib/util/encode/base_n.cc
deleted file mode 100644 (file)
index e0c37e5..0000000
+++ /dev/null
@@ -1,494 +0,0 @@
-// Copyright (C) 2010-2022 Internet Systems Consortium, Inc. ("ISC")
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#include <config.h>
-
-#include <util/encode/base32hex_from_binary.h>
-#include <util/encode/binary_from_base32hex.h>
-#include <util/encode/base16_from_binary.h>
-#include <util/encode/binary_from_base16.h>
-#include <util/encode/base32hex.h>
-#include <util/encode/base64.h>
-
-#include <exceptions/exceptions.h>
-#include <exceptions/isc_assert.h>
-
-#include <boost/archive/iterators/base64_from_binary.hpp>
-#include <boost/archive/iterators/binary_from_base64.hpp>
-#include <boost/archive/iterators/transform_width.hpp>
-#ifdef HAVE_BOOST_INTEGER_COMMON_FACTOR_HPP
-#include <boost/integer/common_factor.hpp>
-#else
-#include <boost/math/common_factor.hpp>
-#endif
-
-#include <stdint.h>
-#include <stdexcept>
-#include <iterator>
-#include <string>
-#include <vector>
-
-using namespace std;
-using namespace boost::archive::iterators;
-
-namespace isc {
-namespace util {
-namespace encode {
-
-// Some versions of clang cannot handle exceptions in unnamed namespaces
-// so this exception is defined in an 'internal' namespace
-namespace clang_unnamed_namespace_workaround {
-// An internally caught exception to unify a few possible cases of the same
-// error.
-class IncompleteBaseInput : public std::exception {
-};
-} // end namespace internal
-
-// In the following anonymous namespace, we provide a generic framework
-// to encode/decode baseN format.  We use the following tools:
-// - boost base64_from_binary/binary_from_base64: provide mapping table for
-//   base64.
-//   These classes take another iterator (Base) as a template argument, and
-//   their dereference operator (operator*()) first retrieves an input value
-//   from Base via Base::operator* and converts the value using their mapping
-//   table.  The converted value is returned as their own operator*.
-// - base{32hex,16}_from_binary/binary_from_base{32hex,16}: provide mapping
-//   table for base32hex and base16.  A straightforward variation of their
-//   base64 counterparts.
-// - EncodeNormalizer/DecodeNormalizer: supplemental filter handling baseN
-//   padding characters (=)
-// - boost transform_width: an iterator framework for handling data stream
-//   per bit-group.  It takes another iterator (Base) and output/input bit
-//   numbers (BitsOut/BitsIn) template arguments.  A transform_width object
-//   internally maintains a bit stream, which can be retrieved per BitsOut
-//   bits via its dereference operator (operator*()).  It builds the stream
-//   by internally iterating over the Base object via Base::operator++ and
-//   Base::operator*, using the least BitsIn bits of the result of
-//   Base::operator*.  In our usage BitsIn for encoding and BitsOut for
-//   decoding are always 8 (# of bits for one byte).
-//
-// Its dereference operator
-//   retrieves BitsIn bits from the result of "*Base" (if necessary it
-//   internally calls ++Base)
-//
-// A conceptual description of how the encoding and decoding work is as
-// follows:
-// Encoding:
-//   input binary data => Normalizer (append sufficient number of 0 bits)
-//                     => transform_width (extract bit groups from the original
-//                                         stream)
-//                     => baseXX_from_binary (convert each bit group to an
-//                                            encoded byte using the mapping)
-// Decoding:
-//   input baseXX text => Normalizer (convert '='s to the encoded characters
-//                                    corresponding to 0, e.g. 'A's in base64)
-//                     => binary_from_baseXX (convert each encoded byte into
-//                                            the original group bit)
-//                     => transform_width (build original byte stream by
-//                                         concatenating the decoded bit
-//                                         stream)
-//
-// Below, we define a set of templated classes to handle different parameters
-// for different encoding algorithms.
-namespace {
-// Common constants used for all baseN encoding.
-const char BASE_PADDING_CHAR = '=';
-const uint8_t BINARY_ZERO_CODE = 0;
-
-// EncodeNormalizer is an input iterator intended to be used as a filter
-// between the binary stream and baseXX_from_binary translator (via
-// transform_width).  An EncodeNormalizer object is configured with two
-// iterators (base and base_end), specifying the head and end of the input
-// stream.  It internally iterators over the original stream, and return
-// each byte of the stream intact via its dereference operator until it
-// reaches the end of the stream.  After that the EncodeNormalizer object
-// will return 0 no matter how many times it is subsequently incremented.
-// This is necessary because the input binary stream may not contain
-// sufficient bits for a full encoded text while baseXX_from_binary expects
-// a sufficient length of input.
-// Note: this class is intended to be used within this implementation file,
-// and assumes "base < base_end" on construction without validating the
-// arguments.  The behavior is undefined if this assumption doesn't hold.
-class EncodeNormalizer {
-public:
-    // Aliases used to enable iterator behavior on this class
-    using iterator_category = input_iterator_tag;
-    using value_type = uint8_t;
-    using difference_type = ptrdiff_t;
-    using pointer = uint8_t*;
-    using reference = uint8_t&;
-
-    EncodeNormalizer(const vector<uint8_t>::const_iterator& base,
-                     const vector<uint8_t>::const_iterator& base_end) :
-        base_(base), base_end_(base_end), in_pad_(false)
-    {}
-    EncodeNormalizer& operator++() { // prefix version
-        increment();
-        return (*this);
-    }
-    EncodeNormalizer operator++(int) { // postfix version
-        const EncodeNormalizer copy = *this;
-        increment();
-        return (copy);
-    }
-    const uint8_t& operator*() const {
-        if (in_pad_) {
-            return (BINARY_ZERO_CODE);
-        } else {
-            return (*base_);
-        }
-    }
-    bool operator==(const EncodeNormalizer& other) const {
-        return (base_ == other.base_);
-    }
-private:
-    void increment() {
-        if (!in_pad_) {
-            ++base_;
-        }
-        if (base_ == base_end_) {
-            in_pad_ = true;
-        }
-    }
-    vector<uint8_t>::const_iterator base_;
-    const vector<uint8_t>::const_iterator base_end_;
-    bool in_pad_;
-};
-
-// DecodeNormalizer is an input iterator intended to be used as a filter
-// between the encoded baseX stream and binary_from_baseXX.
-// A DecodeNormalizer object is configured with three string iterators
-// (base, base_beginpad, and base_end), specifying the head of the string,
-// the beginning position of baseX padding (when there's padding), and
-// end of the string, respectively.  It internally iterators over the original
-// stream, and return each character of the encoded string via its dereference
-// operator until it reaches base_beginpad.  After that the DecodeNormalizer
-// will return the encoding character corresponding to the all-0 value
-// (which is specified on construction via base_zero_code.  see also
-// BaseZeroCode below).  This translation is necessary because
-// binary_from_baseXX doesn't accept the padding character (i.e. '=').
-// Note: this class is intended to be used within this implementation file,
-// and for simplicity assumes "base < base_beginpad <= base_end" on
-// construction without validating the arguments.  The behavior is undefined
-// if this assumption doesn't hold.
-class DecodeNormalizer {
-public:
-    // Aliases used to enable iterator behavior on this class
-    using iterator_category = input_iterator_tag;
-    using value_type = char;
-    using difference_type = ptrdiff_t;
-    using pointer = char*;
-    using reference = char&;
-
-    DecodeNormalizer(const char base_zero_code,
-                     const string::const_iterator& base,
-                     const string::const_iterator& base_beginpad,
-                     const string::const_iterator& base_end,
-                     size_t* char_count) :
-        base_zero_code_(base_zero_code),
-        base_(base), base_beginpad_(base_beginpad), base_end_(base_end),
-        in_pad_(false), char_count_(char_count)
-    {
-        // Skip beginning spaces, if any.  We need do it here because
-        // otherwise the first call to operator*() would be confused.
-        skipSpaces();
-    }
-    DecodeNormalizer& operator++() {
-        if (base_ < base_end_) {
-            ++*char_count_;
-        }
-        ++base_;
-        skipSpaces();
-        if (base_ == base_beginpad_) {
-            in_pad_ = true;
-        }
-        return (*this);
-    }
-    void skipSpaces() {
-        // If (char is signed and) *base_ < 0, on Windows platform with Visual
-        // Studio compiler it may trigger _ASSERTE((unsigned)(c + 1) <= 256);
-        // so make sure that the parameter of isspace() is larger than 0.
-        // We don't simply cast it to unsigned char to avoid confusing the
-        // isspace() implementation with a possible extension for values
-        // larger than 127.  Also note the check is not ">= 0"; for systems
-        // where char is unsigned that would always be true and would possibly
-        // trigger a compiler warning that could stop the build.
-        while (base_ != base_end_ && *base_ > 0 && isspace(*base_)) {
-            ++base_;
-        }
-    }
-    const char& operator*() const {
-        if (base_ == base_end_) {
-            // binary_from_baseX can call this operator when it needs more bits
-            // even if the internal iterator (base_) has reached its end
-            // (if that happens it means the input is an incomplete baseX
-            // string and should be rejected).  So this is the only point
-            // we can catch and reject this type of invalid input.
-            //
-            // More recent versions of Boost fixed the behavior and the
-            // out-of-range call to this operator doesn't happen.  It's good,
-            // but in that case we need to catch incomplete baseX input in
-            // a different way.  It's done via char_count_ and after the
-            // completion of decoding.
-
-            // throw this now and convert it
-            throw clang_unnamed_namespace_workaround::IncompleteBaseInput();
-        }
-        if (*base_ == BASE_PADDING_CHAR) {
-            // Padding can only happen at the end of the input string.  We can
-            // detect any violation of this by checking in_pad_, which is
-            // true iff we are on or after the first valid sequence of padding
-            // characters.
-            if (in_pad_) {
-                return (base_zero_code_);
-            } else {
-                isc_throw(BadValue, "Intermediate padding found");
-            }
-        } else {
-            return (*base_);
-        }
-    }
-    bool operator==(const DecodeNormalizer& other) const {
-        return (base_ == other.base_);
-    }
-private:
-    const char base_zero_code_;
-    string::const_iterator base_;
-    const string::const_iterator base_beginpad_;
-    const string::const_iterator base_end_;
-    bool in_pad_;
-    // Store number of non-space decoded characters (incl. pad) here.  Define
-    // it as a pointer so we can carry it over to any copied objects.
-    size_t* char_count_;
-};
-
-// BitsPerChunk: number of bits to be converted using the baseN mapping table.
-//               e.g. 6 for base64.
-// BaseZeroCode: the byte character that represents a value of 0 in
-//               the corresponding encoding.  e.g. 'A' for base64.
-// Encoder: baseX_from_binary<transform_width<EncodeNormalizer,
-//                                            BitsPerChunk, 8> >
-// Decoder: transform_width<binary_from_baseX<DecodeNormalizer>,
-//                          8, BitsPerChunk>
-template <int BitsPerChunk, char BaseZeroCode,
-          typename Encoder, typename Decoder>
-struct BaseNTransformer {
-    static string encode(const vector<uint8_t>& binary);
-    static void decode(const char* algorithm,
-                       const string& base64, vector<uint8_t>& result);
-
-    // BITS_PER_GROUP is the number of bits for the smallest possible (non
-    // empty) bit string that can be converted to a valid baseN encoded text
-    // without padding.  It's the least common multiple of 8 and BitsPerChunk,
-    // e.g. 24 for base64.
-    static const int BITS_PER_GROUP =
-#ifdef HAVE_BOOST_INTEGER_COMMON_FACTOR_HPP
-        boost::integer::static_lcm<BitsPerChunk, 8>::value;
-#else
-        boost::math::static_lcm<BitsPerChunk, 8>::value;
-#endif
-
-    // MAX_PADDING_CHARS is the maximum number of padding characters
-    // that can appear in a valid baseN encoded text.
-    // It's group_len - chars_for_byte, where group_len is the number of
-    // encoded characters to represent BITS_PER_GROUP bits, and
-    // chars_for_byte is the number of encoded character that is needed to
-    // represent a single byte, which is ceil(8 / BitsPerChunk).
-    // For example, for base64 we need two encoded characters to represent a
-    // byte, and each group consists of 4 encoded characters, so
-    // MAX_PADDING_CHARS is 4 - 2 = 2.
-    static const int MAX_PADDING_CHARS =
-        BITS_PER_GROUP / BitsPerChunk -
-        (8 / BitsPerChunk + ((8 % BitsPerChunk) == 0 ? 0 : 1));
-};
-
-template <int BitsPerChunk, char BaseZeroCode,
-          typename Encoder, typename Decoder>
-string
-BaseNTransformer<BitsPerChunk, BaseZeroCode, Encoder, Decoder>::encode(
-    const vector<uint8_t>& binary)
-{
-    // calculate the resulting length.
-    size_t bits = binary.size() * 8;
-    if (bits % BITS_PER_GROUP > 0) {
-        bits += (BITS_PER_GROUP - (bits % BITS_PER_GROUP));
-    }
-    const size_t len = bits / BitsPerChunk;
-
-    string result;
-    result.reserve(len);
-    result.assign(Encoder(EncodeNormalizer(binary.begin(), binary.end())),
-                  Encoder(EncodeNormalizer(binary.end(), binary.end())));
-    isc_throw_assert(len >= result.length());
-    result.append(len - result.length(), BASE_PADDING_CHAR);
-    return (result);
-}
-
-template <int BitsPerChunk, char BaseZeroCode,
-          typename Encoder, typename Decoder>
-void
-BaseNTransformer<BitsPerChunk, BaseZeroCode, Encoder, Decoder>::decode(
-    const char* const algorithm,
-    const string& input,
-    vector<uint8_t>& result)
-{
-    // enumerate the number of trailing padding characters (=), ignoring
-    // white spaces.  since baseN_from_binary doesn't accept padding,
-    // we handle it explicitly.
-    size_t padchars = 0;
-    string::const_reverse_iterator srit = input.rbegin();
-    string::const_reverse_iterator srit_end = input.rend();
-    while (srit != srit_end) {
-        char ch = *srit;
-        if (ch == BASE_PADDING_CHAR) {
-            if (++padchars > MAX_PADDING_CHARS) {
-                isc_throw(BadValue, "Too many " << algorithm
-                          << " padding characters: " << input);
-            }
-        } else if (!(ch > 0 && isspace(ch))) {
-            // see the note for DecodeNormalizer::skipSpaces() above for ch > 0
-            break;
-        }
-        ++srit;
-    }
-    // then calculate the number of padding bits corresponding to the padding
-    // characters.  In general, the padding bits consist of all-zero
-    // trailing bits of the last encoded character followed by zero bits
-    // represented by the padding characters:
-    // 1st pad  2nd pad  3rd pad...
-    // +++===== =======  ===...    (+: from encoded chars, =: from pad chars)
-    // 0000...0 0......0 000...
-    // 0      7 8     15 16.... (bits)
-    // The number of bits for the '==...' part is padchars * BitsPerChunk.
-    // So the total number of padding bits is the smallest multiple of 8
-    // that is >= padchars * BitsPerChunk.
-    // (Below, note the common idiom of the bitwise AND with ~7.  It clears the
-    // lowest three bits, so has the effect of rounding the result down to the
-    // nearest multiple of 8)
-    const size_t padbits = (padchars * BitsPerChunk + 7) & ~7;
-
-    // In some encoding algorithm, it could happen that a padding byte would
-    // contain a full set of encoded bits, which is not allowed by definition
-    // of padding.  For example, if BitsPerChunk is 5, the following
-    // representation could happen:
-    // ++00000= (+: from encoded chars, 0: encoded char for '0', =: pad chars)
-    // 0      7 (bits)
-    // This must actually be encoded as follows:
-    // ++======
-    // 0      7 (bits)
-    // The following check rejects this type of invalid encoding.
-    if (padbits > BitsPerChunk * (padchars + 1)) {
-        isc_throw(BadValue, "Invalid " << algorithm << " padding: " << input);
-    }
-
-    // convert the number of bits in bytes for convenience.
-    const size_t padbytes = padbits / 8;
-
-    try {
-        size_t char_count = 0;
-        result.assign(Decoder(DecodeNormalizer(BaseZeroCode, input.begin(),
-                                               srit.base(), input.end(),
-                                               &char_count)),
-                      Decoder(DecodeNormalizer(BaseZeroCode, input.end(),
-                                               input.end(), input.end(),
-                                               NULL)));
-
-        // Number of bits of the conversion result including padding must be
-        // a multiple of 8; otherwise the decoder reaches the end of input
-        // with some incomplete bits of data, which is invalid.
-        if (((char_count * BitsPerChunk) % 8) != 0) {
-            // catch this immediately below
-            throw clang_unnamed_namespace_workaround::IncompleteBaseInput();
-        }
-    } catch (const clang_unnamed_namespace_workaround::IncompleteBaseInput&) {
-        // we unify error handling for incomplete input here.
-        isc_throw(BadValue, "Incomplete input for " << algorithm
-                  << ": " << input);
-    } catch (const dataflow_exception& ex) {
-        // convert any boost exceptions into our local one.
-        isc_throw(BadValue, ex.what());
-    }
-
-    // Confirm the original BaseX text is the canonical encoding of the
-    // data, that is, that the first byte of padding is indeed 0.
-    // (DecodeNormalizer and binary_from_baseXX ensure that the rest of the
-    // padding is all zero).
-    isc_throw_assert(result.size() >= padbytes);
-    if (padbytes > 0 && *(result.end() - padbytes) != 0) {
-            isc_throw(BadValue, "Non 0 bits included in " << algorithm
-                      << " padding: " << input);
-    }
-
-    // strip the padded zero-bit fields
-    result.resize(result.size() - padbytes);
-}
-
-//
-// Instantiation for BASE-64
-//
-typedef
-base64_from_binary<transform_width<EncodeNormalizer, 6, 8> > base64_encoder;
-typedef
-transform_width<binary_from_base64<DecodeNormalizer>, 8, 6> base64_decoder;
-typedef BaseNTransformer<6, 'A', base64_encoder, base64_decoder>
-Base64Transformer;
-
-//
-// Instantiation for BASE-32HEX
-//
-typedef
-base32hex_from_binary<transform_width<EncodeNormalizer, 5, 8> >
-base32hex_encoder;
-typedef
-transform_width<binary_from_base32hex<DecodeNormalizer>, 8, 5>
-base32hex_decoder;
-typedef BaseNTransformer<5, '0', base32hex_encoder, base32hex_decoder>
-Base32HexTransformer;
-
-//
-// Instantiation for BASE-16 (HEX)
-//
-typedef
-base16_from_binary<transform_width<EncodeNormalizer, 4, 8> > base16_encoder;
-typedef
-transform_width<binary_from_base16<DecodeNormalizer>, 8, 4> base16_decoder;
-typedef BaseNTransformer<4, '0', base16_encoder, base16_decoder>
-Base16Transformer;
-}
-
-string
-encodeBase64(const vector<uint8_t>& binary) {
-    return (Base64Transformer::encode(binary));
-}
-
-void
-decodeBase64(const string& input, vector<uint8_t>& result) {
-    Base64Transformer::decode("base64", input, result);
-}
-
-string
-encodeBase32Hex(const vector<uint8_t>& binary) {
-    return (Base32HexTransformer::encode(binary));
-}
-
-void
-decodeBase32Hex(const string& input, vector<uint8_t>& result) {
-    Base32HexTransformer::decode("base32hex", input, result);
-}
-
-string
-encodeHex(const vector<uint8_t>& binary) {
-    return (Base16Transformer::encode(binary));
-}
-
-void
-decodeHex(const string& input, vector<uint8_t>& result) {
-    Base16Transformer::decode("base16", input, result);
-}
-
-} // namespace encode
-} // namespace util
-} // namespace isc
diff --git a/src/lib/util/encode/binary_from_base16.h b/src/lib/util/encode/binary_from_base16.h
deleted file mode 100644 (file)
index f913dd0..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-#ifndef BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_HPP
-#define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_HPP
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// binary_from_base16.h (derived from boost binary_from_base64.hpp)
-
-// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
-// Use, modification and distribution is subject to the Boost Software
-// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-//  See http://www.boost.org for updates, documentation, and revision history.
-
-#include <cassert>
-
-// See binary_from_base32hex.h for why we need _from_base64.hpp here.
-#include <boost/archive/iterators/binary_from_base64.hpp>
-
-#include <exceptions/exceptions.h>
-
-namespace boost { 
-namespace archive {
-namespace iterators {
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// convert base16 characters to binary data
-
-namespace detail {
-
-template<class CharType>
-struct to_4_bit {
-    typedef CharType result_type;
-    CharType operator()(CharType t) const{
-        const signed char lookup_table[] = {
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 00-0f
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 10-1f
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 20-2f
-             0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, // 30-3f
-            -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 40-4f
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 50-5f
-            -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1  // 60-6f
-        };
-        BOOST_STATIC_ASSERT(0x70 == sizeof(lookup_table));
-        signed char value = -1;
-        if((unsigned)t < sizeof(lookup_table))
-            value = lookup_table[(unsigned)t];
-        if(-1 == value) { 
-            isc_throw(isc::BadValue,
-                      "attempt to decode a value not in base16 char set");
-        }
-        return (value);
-    }
-};
-
-} // namespace detail
-
-// note: what we would like to do is
-// template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
-//  typedef transform_iterator<
-//      from_4_bit<CharType>,
-//      transform_width<Base, 4, sizeof(Base::value_type) * 8, CharType>
-//  > base16_from_binary;
-// but C++ won't accept this.  Rather than using a "type generator" and
-// using a different syntax, make a derivation which should be equivalent.
-//
-// Another issue addressed here is that the transform_iterator doesn't have
-// a templated constructor.  This makes it incompatible with the dataflow
-// ideal.  This is also addressed here.
-
-template<
-    class Base, 
-    class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
->
-class binary_from_base16 : public
-    transform_iterator<
-        detail::to_4_bit<CharType>,
-        Base
-    >
-{
-    friend class boost::iterator_core_access;
-    typedef transform_iterator<
-        detail::to_4_bit<CharType>,
-        Base
-    > super_t;
-public:
-    // make composable by using templated constructor
-    template<class T>
-    binary_from_base16(T start) :
-        super_t(
-            Base(static_cast<T>(start)),
-            detail::to_4_bit<CharType>()
-        )
-    {}
-    // intel 7.1 doesn't like default copy constructor
-    binary_from_base16(const binary_from_base16 & rhs) : 
-        super_t(
-            Base(rhs.base_reference()),
-            detail::to_4_bit<CharType>()
-        )
-    {}
-//    binary_from_base16(){};
-};
-
-} // namespace iterators
-} // namespace archive
-} // namespace boost
-
-#endif // BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE16_HPP
-
-// Local Variables: 
-// mode: c++
-// End: 
diff --git a/src/lib/util/encode/binary_from_base32hex.h b/src/lib/util/encode/binary_from_base32hex.h
deleted file mode 100644 (file)
index 2911789..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-#ifndef BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
-#define BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// binary_from_base32hex.h (derived from boost binary_from_base64.hpp)
-
-// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
-// Use, modification and distribution is subject to the Boost Software
-// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-//  See http://www.boost.org for updates, documentation, and revision history.
-
-#include <cassert>
-
-// We use the same boost header files used in "_from_base64".  Since the
-// precise path to these headers may vary depending on the boost version we
-// simply include the base64 header here.
-#include <boost/archive/iterators/binary_from_base64.hpp>
-
-#include <exceptions/exceptions.h>
-
-namespace boost { 
-namespace archive {
-namespace iterators {
-
-/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
-// convert base32hex characters to binary data
-
-namespace detail {
-
-template<class CharType>
-struct to_5_bit {
-    typedef CharType result_type;
-    CharType operator()(CharType t) const{
-        const signed char lookup_table[] = {
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 00-0f
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 10-1f
-            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 20-2f
-             0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, // 30-3f
-            -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, // 40-4f
-            25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 50-5f
-            -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, // 60-6f
-            25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1,-1  // 70-7f
-        };
-        BOOST_STATIC_ASSERT(0x80 == sizeof(lookup_table));
-        signed char value = -1;
-        if((unsigned)t < sizeof(lookup_table))
-            value = lookup_table[(unsigned)t];
-        if(-1 == value) { 
-            isc_throw(isc::BadValue,
-                      "attempt to decode a value not in base32hex char set");
-        }
-        return (value);
-    }
-};
-
-} // namespace detail
-
-// note: what we would like to do is
-// template<class Base, class CharType = BOOST_DEDUCED_TYPENAME Base::value_type>
-//  typedef transform_iterator<
-//      from_5_bit<CharType>,
-//      transform_width<Base, 5, sizeof(Base::value_type) * 8, CharType>
-//  > base32hex_from_binary;
-// but C++ won't accept this.  Rather than using a "type generator" and
-// using a different syntax, make a derivation which should be equivalent.
-//
-// Another issue addressed here is that the transform_iterator doesn't have
-// a templated constructor.  This makes it incompatible with the dataflow
-// ideal.  This is also addressed here.
-
-template<
-    class Base, 
-    class CharType = BOOST_DEDUCED_TYPENAME boost::iterator_value<Base>::type
->
-class binary_from_base32hex : public
-    transform_iterator<
-        detail::to_5_bit<CharType>,
-        Base
-    >
-{
-    friend class boost::iterator_core_access;
-    typedef transform_iterator<
-        detail::to_5_bit<CharType>,
-        Base
-    > super_t;
-public:
-    // make composable by using templated constructor
-    template<class T>
-    binary_from_base32hex(T start) :
-        super_t(
-            Base(static_cast<T>(start)),
-            detail::to_5_bit<CharType>()
-        )
-    {}
-    // intel 7.1 doesn't like default copy constructor
-    binary_from_base32hex(const binary_from_base32hex & rhs) : 
-        super_t(
-            Base(rhs.base_reference()),
-            detail::to_5_bit<CharType>()
-        )
-    {}
-//    binary_from_base32hex(){};
-};
-
-} // namespace iterators
-} // namespace archive
-} // namespace boost
-
-#endif // BOOST_ARCHIVE_ITERATORS_BINARY_FROM_BASE32HEX_HPP
-
-// Local Variables: 
-// mode: c++
-// End: 
diff --git a/src/lib/util/encode/encode.cc b/src/lib/util/encode/encode.cc
new file mode 100644 (file)
index 0000000..52b15e6
--- /dev/null
@@ -0,0 +1,280 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
+#include <util/encode/encode.h>
+
+#include <iostream>
+#include <stdint.h>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+using namespace std;
+
+namespace isc {
+namespace util {
+namespace encode {
+
+std::string
+encodeBaseN(const std::vector<uint8_t>& input, const char* digit_set, size_t bits_per_digit,
+       size_t digits_per_group, const char pad_char) {
+    std::string encoded_output;
+    if (input.empty()) {
+        return(encoded_output);
+    }
+
+    // Turn the input data into a "bit stream"
+    /// @todo Can we devize a bit-stream class that can iterate over the input
+    /// without copying it?  The weakness here is inbits could be rather large
+    /// for long strings since it input size * 8 bytes.
+    bool inbits[input.size() * 8];
+    bool* inbit = &inbits[0];
+    for (auto b : input) {
+        for (auto i = 0; i < 8; i++) {
+            bool val = b & 0x80;
+            *inbit++ = val;
+            b <<= 1;
+        }
+    }
+
+    // Now encode the bit stream.
+    int cnt = 0;
+    int digit_idx = 0;
+    auto inbit_end = inbit;
+    inbit = &inbits[0];
+    for (inbit = &inbits[0]; inbit != inbit_end; ++inbit) {
+        if (cnt < bits_per_digit) {
+            // Shift the index one to accomodate next bit.
+            digit_idx <<= 1;
+        } else {
+            // Have a complete digit index, look it the digit and add it.
+            encoded_output.push_back(digit_set[digit_idx]);
+            digit_idx = 0;
+            cnt = 0;
+        }
+
+        // Add the current bit to the digit index.
+        digit_idx |= *inbit;
+        ++cnt;
+    }
+
+    // We've exhausted bits, but have left over
+    if (cnt) {
+        digit_idx <<= (bits_per_digit - cnt);
+        encoded_output.push_back(digit_set[digit_idx]);
+    }
+
+    // Add padding as needed.
+    if (digits_per_group) {
+        auto rem = encoded_output.size() % digits_per_group;
+        if (rem) {
+            auto need = digits_per_group - rem + 1;
+            while (--need) {
+                encoded_output.push_back(pad_char);
+            }
+        }
+    }
+
+    return(encoded_output);
+}
+
+void
+decodeBaseN(const std::string& algorithm,
+            const std::string& encoded_str, std::vector<uint8_t>& output,
+            const uint8_t* lookup_table,
+            size_t bits_per_digit,
+            size_t digits_per_group,
+            const char pad_char,
+            size_t max_pad) {
+
+    output.clear();
+    bool inbits[encoded_str.size() * bits_per_digit];
+    bool* inbit = &inbits[0];
+    size_t dig_cnt = 0;
+    size_t pad_cnt = 0;
+    size_t shift_bits = 8 - bits_per_digit;
+    for (const auto enc_digit : encoded_str) {
+        if (pad_char && enc_digit == pad_char) {
+           pad_cnt++;
+           continue;
+        }
+
+        // translate the b64 digit to bits.
+        uint8_t dig_bits = lookup_table[static_cast<uint8_t>(enc_digit)];
+
+        if (dig_bits == 0xee) {
+            // skip whitespace
+            continue;
+        }
+
+        if (dig_bits == 0xff) {
+            isc_throw(isc::BadValue, "attempt to decode a value not in "
+                      << algorithm << " char set" << ": " << encoded_str);
+        }
+
+        if (pad_cnt) {
+            isc_throw(isc::BadValue, "pad mixed with digits in "
+                      << algorithm << ": " << encoded_str);
+        }
+
+        dig_cnt++;
+        dig_bits <<= shift_bits;
+        for (auto i = 0; i < bits_per_digit; ++i) {
+            *inbit++ = ((dig_bits & 0x80) == 0x80);
+            dig_bits <<= 1;
+        }
+    }
+
+    if (pad_char) {
+        // Check for invalid number of pad characters.
+        if (pad_cnt > max_pad) {
+            isc_throw(isc::BadValue, "too many pad characters for "
+                      << algorithm << ": " << encoded_str);
+        }
+
+        // Check for invalid number of pad characters.
+        /// @todo is this valid
+        const size_t padbits = ((pad_cnt * bits_per_digit) + 7) & ~7;
+        if (padbits > bits_per_digit * (pad_cnt + 1)) {
+            isc_throw(isc::BadValue, "Invalid padding for "
+                      << algorithm << ": " << encoded_str);
+        }
+    }
+
+    // Check for an invalid total of encoded characters.
+    if ((pad_cnt + dig_cnt) % digits_per_group) {
+        isc_throw (isc::BadValue, "Incomplete input for "
+                   << algorithm << ": " << encoded_str);
+    }
+
+    int cnt = 0;
+    int digit_idx = 0;
+
+    auto inbit_end = inbit;
+    inbit = &inbits[0];
+    for (inbit = &inbits[0]; inbit != inbit_end; ++inbit) {
+        if (cnt < 8) {
+            digit_idx <<= 1;
+        } else {
+            output.push_back(digit_idx);
+            digit_idx = 0;
+            cnt = 0;
+        }
+
+        digit_idx |= *inbit;
+        ++cnt;
+    }
+
+    if (cnt == 8) {
+        // Whole one left to add.
+        output.push_back(digit_idx);
+    } else if (cnt && digit_idx) {
+        // Left over bits that are not zero.
+        isc_throw(BadValue, "non-zero bits left over " << encoded_str);
+    }
+}
+
+
+string
+encodeBase64(const vector<uint8_t>& binary) {
+    static char B64_DIG[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                            "abcdefghijklmnopqrstuvwxyz"
+                            "0123456789"
+                             "+/";
+    return(encodeBaseN(binary, B64_DIG, 6, 4, '='));
+}
+
+void
+decodeBase64 (const std::string& encoded_str, std::vector<uint8_t>& output) {
+    static const uint8_t lookup_table[] = {
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff,0xff, // 00-0f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 10-1f
+        0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,62,0xff,0xff,0xff,63,     // 20-2f
+        52,53,54,55,56,57,58,59,60,61,0xff,0xff,0xff, 0,0xff,0xff,                       // 30-3f
+        0xff, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,                               // 40-4f
+        15,16,17,18,19,20,21,22,23,24,25,0xff,0xff,0xff,0xff,0xff,                       // 50-5f
+        0xff,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,                               // 60-6f
+        41,42,43,44,45,46,47,48,49,50,51,0xff,0xff,0xff,0xff,0xff,                       // 70-7f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 80-8f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 90-9f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // a0-af
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // b0-bf
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // c0-cf
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // d0-df
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // e0-ef
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff  // f0-ff
+    };
+
+   decodeBaseN("base64", encoded_str, output, lookup_table, 6, 4, '=', 2);
+}
+
+string
+encodeBase32Hex(const vector<uint8_t>& binary) {
+    static char B32_DIG[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
+    return(encodeBaseN(binary, B32_DIG, 5, 8, '='));
+}
+
+void
+decodeBase32Hex(const std::string& encoded_str, std::vector<uint8_t>& output) {
+    static const uint8_t lookup_table[] = {
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff,0xff, // 00-0f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 10-1f
+        0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 20-2f
+        0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xff,0xff,0xff,0xff,0xff,0xff,                      // 30-3f
+        0xff,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,                               // 40-4f
+        25,26,27,28,29,30,31,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,               // 50-5f
+        0xff,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,                               // 60-6f
+        25,26,27,28,29,30,31,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,               // 70-7f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 80-8f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 90-9f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // a0-af
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // b0-bf
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // c0-cf
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // d0-df
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // e0-ef
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff  // f0-ff
+    };
+
+   decodeBaseN("base32hex", encoded_str, output, lookup_table, 5, 8, '=', 6);
+}
+
+string
+encodeHex(const vector<uint8_t>& binary) {
+    static char B16_DIG[] = "0123456789ABCDEF";
+    return(encodeBaseN(binary, B16_DIG, 4, 1, 0));
+}
+
+void
+decodeHex(const string& encoded_str, vector<uint8_t>& output) {
+    static const uint8_t lookup_table[] = {
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff,0xff, // 00-0f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 10-1f
+        0xee,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 20-2f
+        0, 1, 2, 3, 4, 5, 6, 7, 8, 9,0xff,0xff,0xff,0xff,0xff,0xff,                      // 30-3f
+        0xff,10,11,12,13,14,15,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,             // 40-4f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 50-5f
+        0xff,10,11,12,13,14,15,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,             // 60-6f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 70-7f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 80-8f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // 90-9f
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // a0-af
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // b0-bf
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // c0-cf
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // d0-df
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // e0-ef
+        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff  // f0-ff
+    };
+
+   decodeBaseN("base16", encoded_str, output, lookup_table, 4, 1, 0, 0);
+}
+
+} // namespace encode
+} // namespace util
+} // namespace isc
diff --git a/src/lib/util/encode/encode.h b/src/lib/util/encode/encode.h
new file mode 100644 (file)
index 0000000..2e6bca0
--- /dev/null
@@ -0,0 +1,70 @@
+// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef ENCODE_H
+#define ENCODE_H
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+
+namespace isc {
+namespace util {
+namespace encode {
+
+/// @brief Encode binary data in the base32-hex format.
+///
+/// @param binary vector object storing the data to be encoded.
+/// @return string containing the base32-hex encoded value.
+std::string encodeBase32Hex(const std::vector<uint8_t>& binary);
+
+/// @brief Decode a base32-hex encoded string into binary data.
+///
+/// @param encoded_str string containing a base32-hex encoded value.
+/// @param[out] output vector into which the decoded binary data is stored.
+/// @throw BadValue if the input string is invalid.
+void decodeBase32Hex(const std::string& encoded_str, std::vector<uint8_t>& output);
+
+/// @brief Encode binary data in the base64 format.
+///
+/// @param binary vector object storing the data to be encoded.
+/// @return string containing the base64 encoded value.
+std::string encodeBase64(const std::vector<uint8_t>& binary);
+
+/// @brief Decode a base64 encoded string into binary data.
+///
+/// @param encoded_str string containing a base64 encoded value.
+/// @param[out] output vector into which the decoded binary data is stored.
+/// @throw BadValue if the input string is invalid.
+void decodeBase64(const std::string& encoded_str, std::vector<uint8_t>& output);
+
+/// @brief Encode binary data in the base16 format.
+///
+/// @param binary vector object containing the data to be encoded.
+/// @return string containing the base16 encoded value.
+std::string encodeHex(const std::vector<uint8_t>& binary);
+
+/// @brief Decode a base16 encoded string into binary data.
+///
+/// @param encoded_str string containing a base16 encoded value.
+/// @param[out] output vector into which the decoded binary data is stored.
+/// @throw BadValue if the input string is invalid.
+void decodeHex(const std::string& encoded_str, std::vector<uint8_t>& output);
+
+/// @brief Encode in hexadecimal inline
+///
+/// @param value the value to encode
+/// @return 0x followed by the value encoded in hexa
+inline std::string toHex(std::string value) {
+    std::vector<uint8_t> bin(value.begin(), value.end());
+    return ("0x" + encodeHex(bin));
+}
+
+} // namespace encode
+} // namespace util
+} // namespace isc
+
+#endif  // ENCODE_H
diff --git a/src/lib/util/encode/hex.h b/src/lib/util/encode/hex.h
deleted file mode 100644 (file)
index de3ac21..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (C) 2009-2016 Internet Systems Consortium, Inc. ("ISC")
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef HEX_H
-#define HEX_H 1
-
-#include <stdint.h>
-#include <string>
-#include <vector>
-
-//
-// Note: this helper module isn't specific to the DNS protocol per se.
-// We should probably move this to somewhere else, possibly in some common
-// utility area.
-//
-
-namespace isc {
-namespace util {
-namespace encode {
-/// \brief Encode binary data in the base16 ('hex') format.
-///
-/// The underlying implementation is shared with \c encodeBase64, and most of
-/// the description except the format (base16) equally applies.
-/// Another notable exception is that the base16 encoding doesn't require
-/// padding, so padding related considerations and the notion of canonical
-/// encoding don't apply.
-///
-/// \param binary A vector object storing the data to be encoded. 
-/// \return A newly created string that stores base16 encoded value for
-/// binary.
-std::string encodeHex(const std::vector<uint8_t>& binary);
-
-/// \brief Decode a text encoded in the base16 ('hex') format into the
-/// original %data.
-///
-/// The underlying implementation is shared with \c decodeBase64, and most
-/// of the description except the format (base16) equally applies.
-/// Another notable exception is that the base16 encoding doesn't require
-/// padding, so padding related considerations and the notion of canonical
-/// encoding don't apply.
-///
-/// \param input A text encoded in the base16 format.
-/// \param result A vector in which the decoded %data is to be stored.
-void decodeHex(const std::string& input, std::vector<uint8_t>& result);
-
-/// \brief Encode in hexadecimal inline
-///
-/// \param value the value to encode
-/// \return 0x followed by the value encoded in hexa
-inline std::string toHex(std::string value) {
-    std::vector<uint8_t> bin(value.begin(), value.end());
-    return ("0x" + encodeHex(bin));
-}
-
-} // namespace encode
-} // namespace util
-} // namespace isc
-
-#endif  // HEX_H
-
-// Local Variables: 
-// mode: c++
-// End: 
index 3dd83d1a9b3ddb1b11b5c02a4a43c068c43a56c7..7c3b2e65e20ed9f90d8d0e712f6013e9e5d8e688 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <config.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/strutil.h>
 
 #include <boost/algorithm/string/classification.hpp>
index 947dc3820c9e5ef177df45f251beae9b875dc4e1..ff68ba7167fbe0a95ee288008b1791873d4c4fab 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <util/encode/base32hex.h>
+#include <util/encode/encode.h>
 
 #include <gtest/gtest.h>
 
index 6843b594dca24988953356a9a395b92fb328aa57..71b4d4214bea2e9dd4951cb8e6562a82b575e01c 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <exceptions/exceptions.h>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 
 #include <gtest/gtest.h>
 
index 1e611b51a30aab3b99c9cbcbeee78ce8b2ac2883..27fa166bbba7b3a36b0cb70d5019c2b825f50a4e 100644 (file)
@@ -13,7 +13,8 @@
 
 #include <exceptions/exceptions.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
+#include <testutils/gtest_utils.h>
 
 #include <gtest/gtest.h>
 
@@ -94,7 +95,12 @@ TEST_F(HexTest, decodeMap) {
         const char ch = toupper(i);
         const size_t pos = encoding_chars.find(ch);
         if (pos == string::npos) {
-            EXPECT_THROW(decodeHex(input, decoded_data), BadValue);
+            if (!std::isspace(ch)) {
+                EXPECT_THROW(decodeHex(input, decoded_data), BadValue) << "input:" << input;
+            } else {
+                EXPECT_NO_THROW_LOG(decodeHex(input, decoded_data));
+                EXPECT_EQ(0, decoded_data.size());
+            }
         } else {
             decodeHex(input, decoded_data);
             EXPECT_EQ(1, decoded_data.size());
index 912b40f0d828beca2a3847be9ad11f0b647862ee..563d4042c3e360445fdacdc59428e0e88e591a03 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <exceptions/exceptions.h>
 #include <util/strutil.h>
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 
 #include <gtest/gtest.h>
 
index 43fe4cdd6f7baa0b6ed13943d468ffaff68ebee6..78f427e651f7f3a91d9d7260e7e2e4aa3a640b60 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <config.h>
 
-#include <util/encode/hex.h>
+#include <util/encode/encode.h>
 #include <util/strutil.h>
 #include <yang/adaptor_host.h>
 
index cada692476d7d65185ab7a87b945956e268911cf..7857143d6658da85576c7a6cd2479ca36f1a2f8a 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <config.h>
 
-#include <util/encode/base64.h>
+#include <util/encode/encode.h>
 #include <yang/adaptor.h>
 #include <yang/translator.h>