// Copyright 2017 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #include #include #include #include #include #include #include "Common/Assert.h" #include "Common/CommonTypes.h" namespace Common::SHA1 { using Digest = std::array; static constexpr size_t DIGEST_LEN = sizeof(Digest); class Context { public: virtual ~Context() = default; virtual void Update(const u8* msg, size_t len) = 0; void Update(std::span msg) { return Update(msg.data(), msg.size()); } void Update(std::string_view msg) { return Update(reinterpret_cast(msg.data()), msg.size()); } virtual Digest Finish() = 0; virtual bool HwAccelerated() const = 0; }; std::unique_ptr CreateContext(); Digest CalculateDigest(const u8* msg, size_t len); template inline Digest CalculateDigest(const std::vector& msg) { static_assert(std::is_trivially_copyable_v); ASSERT(std::numeric_limits::max() / sizeof(T) >= msg.size()); return CalculateDigest(reinterpret_cast(msg.data()), sizeof(T) * msg.size()); } inline Digest CalculateDigest(const std::string_view& msg) { return CalculateDigest(reinterpret_cast(msg.data()), msg.size()); } template inline Digest CalculateDigest(const std::array& msg) { static_assert(std::is_trivially_copyable_v); return CalculateDigest(reinterpret_cast(msg.data()), sizeof(msg)); } std::string DigestToString(const Digest& digest); } // namespace Common::SHA1