#pragma once #include #include #include #include #include #include #include #include namespace Void::Crypto { enum class HashAlgorithm { Sha1, Sha256, Sha512 }; using Digest = std::vector; class Hasher { public: [[nodiscard]] static Void::Result::Result create(HashAlgorithm algorithm); ~Hasher(); Hasher(Hasher&&) noexcept; Hasher& operator=(Hasher&&) noexcept; Hasher(const Hasher&) = delete; Hasher& operator=(const Hasher&) = delete; [[nodiscard]] Void::Result::Result update(std::span data); [[nodiscard]] Void::Result::Result update(std::string_view data); /// Finalize this hash. Calling finalize or update again is an /// error. [[nodiscard]] Void::Result::Result finalize(); private: struct Impl; std::unique_ptr m_impl; explicit Hasher(std::unique_ptr impl) noexcept; }; [[nodiscard]] Void::Result::Result hash(HashAlgorithm algorithm, std::span data); [[nodiscard]] Void::Result::Result hash(HashAlgorithm algorithm, std::string_view data); [[nodiscard]] Void::Result::Result hashFile(HashAlgorithm algorithm, const std::filesystem::path& path); [[nodiscard]] Void::Result::Result sha1(std::span data); [[nodiscard]] Void::Result::Result sha1(std::string_view data); [[nodiscard]] Void::Result::Result sha256(std::span data); [[nodiscard]] Void::Result::Result sha256(std::string_view data); [[nodiscard]] Void::Result::Result sha512(std::span data); [[nodiscard]] Void::Result::Result sha512(std::string_view data); [[nodiscard]] Void::Result::Result sha1File(const std::filesystem::path& path); [[nodiscard]] Void::Result::Result sha256File(const std::filesystem::path& path); [[nodiscard]] Void::Result::Result sha512File(const std::filesystem::path& path); inline constexpr std::size_t Ed25519PublicKeySize = 32; inline constexpr std::size_t Ed25519SignatureSize = 64; /// Verify an Ed25519 detached signature over the exact message bytes. /// Invalid key/signature sizes are errors; a well-formed but invalid /// signature returns false. [[nodiscard]] Void::Result::Result verifyEd25519(std::span message, std::span signature, std::span publicKey); } // namespace Void::Crypto