Files
scylladb/utils/hashers.hh
Michał Chojnowski 2bd393849c utils/hashers: add get_sha256()
Add a helper function which computes the SHA256 for a blob.
We will use it to compute identifiers for SSTable compression
dictionaries later.
2025-04-01 00:07:28 +02:00

45 lines
1.2 KiB
C++

/*
* Copyright (C) 2019-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#pragma once
#include <memory>
#include "bytes_fwd.hh"
#include "utils/hashing.hh"
template<typename H>
concept HasherReturningBytes = HasherReturning<H, bytes>;
class md5_hasher;
template <typename T, size_t size> class cryptopp_hasher : public hasher {
struct impl;
std::unique_ptr<impl> _impl;
public:
cryptopp_hasher();
~cryptopp_hasher();
cryptopp_hasher(cryptopp_hasher&&) noexcept;
cryptopp_hasher(const cryptopp_hasher&);
cryptopp_hasher& operator=(cryptopp_hasher&&) noexcept;
cryptopp_hasher& operator=(const cryptopp_hasher&);
bytes finalize();
std::array<uint8_t, size> finalize_array();
void update(const char* ptr, size_t length) noexcept override;
// Use update and finalize to compute the hash over the full view.
static bytes calculate(const std::string_view& s);
};
class md5_hasher final : public cryptopp_hasher<md5_hasher, 16> {};
class sha256_hasher final : public cryptopp_hasher<sha256_hasher, 32> {};
std::array<std::byte, 32> get_sha256(std::span<const std::byte>);