/* * Copyright (C) 2018 ScyllaDB */ /* * This file is part of Scylla. * * Scylla is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Scylla is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Scylla. If not, see . */ #pragma once #include "digest_algorithm.hh" #include "hashers.hh" #include "xx_hasher.hh" #include #include namespace query { struct noop_hasher { void update(const char* ptr, size_t length) noexcept { } std::array finalize_array() { return std::array(); }; }; class digester final { std::variant _impl; public: explicit digester(digest_algorithm algo) { switch (algo) { case digest_algorithm::MD5: _impl = md5_hasher(); break; case digest_algorithm::xxHash: _impl = xx_hasher(); break; case digest_algorithm::legacy_xxHash_without_null_digest: _impl = legacy_xx_hasher_without_null_digest(); break; case digest_algorithm ::none: _impl = noop_hasher(); break; } } template void feed_hash(const T& value, Args&&... args) { std::visit([&] (auto& hasher) noexcept -> void { ::feed_hash(hasher, value, std::forward(args)...); }, _impl); }; std::array finalize_array() { return std::visit([&] (auto& hasher) { return hasher.finalize_array(); }, _impl); } }; using default_hasher = xx_hasher; template using using_hash_of_hash = std::negation, std::is_same>>; template inline constexpr bool using_hash_of_hash_v = using_hash_of_hash::value; }